Last active
March 6, 2017 19:49
-
-
Save jacob-beltran/910bd1d7ede863cd8178c0ecb40a075f to your computer and use it in GitHub Desktop.
React Performance: Timeout Management Example
This file contains 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
// How to propery cancel timeouts/intervals | |
compnentDidMount() { | |
this._timeoutId = setTimeout( this.doFutureStuff, 1000 ); | |
this._intervalId = setInterval( this.doStuffRepeatedly, 5000 ); | |
} | |
componentWillUnmount() { | |
/* | |
ProTip: If the operation already completed, or the value is undefinded | |
these functions don't give a damn | |
*/ | |
clearTimeout( this._timeoutId ); | |
clearInterval( this._intervalId ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment