2

when i click on one of the Links in the mobile view, it renders a new component for the product details page.

However the rendered view always starts at the bottom ..

how can i change this to always display the new component from the top ??

DarkArtistry
  • 434
  • 1
  • 6
  • 22
  • 1
    Your Question has already been answered [here](https://stackoverflow.com/questions/33188994/scroll-to-the-top-of-the-page-after-render-in-react-js). :) – Sebastian Waldbauer Jan 20 '19 at 13:40
  • thank you @SebastianWaldbauer – DarkArtistry Jan 20 '19 at 13:43
  • Possible duplicate of [Scroll to the top of the page after render in react.js](https://stackoverflow.com/questions/33188994/scroll-to-the-top-of-the-page-after-render-in-react-js) – Phisn Jan 20 '19 at 15:04

2 Answers2

2

You can try this :

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

for stateless component with the help of hooks you can achieve this by doing:

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