0

I want my page to scroll to the top on page load, it semi works just now, but if I have scrolled down further than the size of my target page it no longer works, seems strange, any simple fix?

useEffect(() => {
    window.scrollTo({ top: 0, behavior: "smooth" });
  }, []);
Whisky-Toad
  • 125
  • 1
  • 6
  • 1
    This question is already answered here https://stackoverflow.com/questions/33188994/scroll-to-the-top-of-the-page-after-render-in-react-js – Arihant Jain May 16 '21 at 08:01

1 Answers1

1

Try with this

window.scrollTo(0, 0)