Skip to content

Instantly share code, notes, and snippets.

@whisher
Created September 19, 2020 13:57
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 whisher/a094f79731dddf5f46970d7ddd07cb54 to your computer and use it in GitHub Desktop.
Save whisher/a094f79731dddf5f46970d7ddd07cb54 to your computer and use it in GitHub Desktop.
const App = () => {
const [num, setNum] = useState(1);
useEffect(() => {
document.addEventListener("click", (ev) => {
setNum(Math.random());
});
return function cleanup() {
document.removeEventListener("click", (ev) => {});
};
}, [num]);
console.log("render");
return (
<div className="App">
<header className="App-header">{num}</header>
</div>
);
};
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment