#Volks help
1 messages · Page 1 of 1 (latest)
Move the handleScroll inside the useEffect function. And update your code like this
useEffect(() => {
const handleScroll = () => {
if (window.scrollY > 300) {
setShowButton(true);
} else {
setShowButton(false);
}
};
window.addEventListener('scroll', handleScroll);
return () => window.removeEventListener('scroll', handleScroll);
}, []);
Here's a demo of this working https://stackblitz.com/edit/nextjs-oxqtvy?devtoolsheight=33&file=components/ScrollComponent.jsx
@blazing falcon thanks, it's not working for me but I'll take a closer look at what differs in our setup