Skip to content

Instantly share code, notes, and snippets.

@jacob-beltran
Last active March 6, 2017 19:49
Show Gist options
  • Save jacob-beltran/910bd1d7ede863cd8178c0ecb40a075f to your computer and use it in GitHub Desktop.
Save jacob-beltran/910bd1d7ede863cd8178c0ecb40a075f to your computer and use it in GitHub Desktop.
React Performance: Timeout Management Example
// 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