Created
July 17, 2019 13:47
-
-
Save Zaggen/deff96b3befefac5019bfe9016955f0a to your computer and use it in GitHub Desktop.
Counter with event state handlers with default fix
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
const Counter = () => { | |
const [count, setCount] = React.useState(0); | |
React.useEffect(() => { | |
const handleScroll = () => { | |
setCount(countState => countState + 1); | |
}; | |
document.addEventListener(“scroll”, handleScroll); | |
// Clean up | |
return () => document.removeEventListener(“scroll”, handleScroll); | |
}, []); | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment