Skip to content

Instantly share code, notes, and snippets.

@Zaggen
Created July 17, 2019 13:47
Show Gist options
  • Save Zaggen/deff96b3befefac5019bfe9016955f0a to your computer and use it in GitHub Desktop.
Save Zaggen/deff96b3befefac5019bfe9016955f0a to your computer and use it in GitHub Desktop.
Counter with event state handlers with default fix
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