¿Es posible usar solo CSS para hacer un desplazamiento suave al hacer clic en un enlace de anclaje en el componente de reacción?
... render( <a href="#smooth-link">Link To There</a> .... <div id="smooth-link"> .... </div> )Hay esto:
/** * Smooth scrolling inside an element */ #my-element { scroll-behavior: smooth; } /** * Smooth scrolling on the whole document */ html { scroll-behavior: smooth; }Pero siento que JS hace un mejor trabajo:
document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); });Así que podrías intentarlo: docs