Web development basic and advance tutorial, php basic tutorial, laravel basic tutorial, React Native tutorial

Sunday, October 17, 2021

Scroll to the top of the page after render in react.js

0 comments

 I have a problem, which I have no ideas, how to solve. In my react component I display a long list of data and few links at the bottom. After clicking on any of this links I fill in the list with new collection of the links and need to scroll to the top.

The problem is - how to scroll to the top after new collection is rendered?

Finally.. I used:

componentDidMount() {
  window.scrollTo(0, 0)
}

EDIT: React v16.8+

useEffect(() => {
  window.scrollTo(0, 0)
}, [])


No comments:

Post a Comment