Last active
May 18, 2022 01:23
-
-
Save ljaviertovar/6583729ae8f2d290863fbe1c9696b2a6 to your computer and use it in GitHub Desktop.
Cleaning up Timeout 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 timerId = setTimeout(() => { | |
// do something | |
timerId = null; | |
}, 3000); | |
// cleanup the timmer when component unmout | |
return () => clearTimeout(timerId); | |
}, []); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment