how to give top in reactjs in js code example
Example 1: toggle class onscroll hook react
const [scroll, setScroll] = useState(0)
useEffect(() => {
document.addEventListener("scroll", () => {
const scrollCheck = window.scrollY < 100
if (scrollCheck !== scroll) {
setScroll(scrollCheck)
}
})
})
Example 2: how to make page scroll to the top jsx
componentDidMount() {
window.scrollTo(0, 0)
}