Skip to content

Instantly share code, notes, and snippets.

@rsturim
Created January 5, 2022 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsturim/e42a333e355efeda87b801c5f1f57338 to your computer and use it in GitHub Desktop.
Save rsturim/e42a333e355efeda87b801c5f1f57338 to your computer and use it in GitHub Desktop.
function App() {
const handleScroll = useCallback(() => {
console.log(window.scrollY);
}, []);
useEffect(() => {
// subscribe to scroll event
window.addEventListener('scroll', handleScroll);
return () => {
// CLEANUP FUNCTION
// unsubscribe scroll event
// when component unmounts
window.removeEventListener('scroll', handleScroll);
};
}, []);
return (
<div>Hello</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment