Created
January 5, 2022 22:35
-
-
Save rsturim/e42a333e355efeda87b801c5f1f57338 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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