Last active
May 18, 2022 04:34
-
-
Save ljaviertovar/28f6597561d91f898599c96f56dfbbff to your computer and use it in GitHub Desktop.
Cleaning up Intervals functions in React
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
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