Skip to content

Instantly share code, notes, and snippets.

@ljaviertovar
Last active May 18, 2022 04:34
Show Gist options
  • Save ljaviertovar/28f6597561d91f898599c96f56dfbbff to your computer and use it in GitHub Desktop.
Save ljaviertovar/28f6597561d91f898599c96f56dfbbff to your computer and use it in GitHub Desktop.
Cleaning up Intervals functions in React
useEffect(() => {
let intervalId = setInterval(() => {
// do something like update the state
}, 1000);
// cleanup the timer when component unmout
return () => clearInterval(interval);
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment