react scroll top button code example

Example 1: scroll to top in react

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

Example 2: scroll to top in react

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

Example 3: how to create scroll to top button in reactjs example code

import React from "react";import ScrollUpButton from "react-scroll-up-button"; //Add this line Here export default class Index extends React.Component {    render() {        return (            <div>                <ScrollUpButton />                //This is all you need to get the default view working            </div>        );    }}