Skip to content

Instantly share code, notes, and snippets.

@FrankGerold
Last active January 24, 2020 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FrankGerold/dc3a1fe6d435fab511ce0750aacdd62c to your computer and use it in GitHub Desktop.
Save FrankGerold/dc3a1fe6d435fab511ce0750aacdd62c to your computer and use it in GitHub Desktop.
React Lifecycle Methods
componentDidMount() {
this.timerID = setInterval(() => this.tick(), 1000 );
}
componentDidUpdate(prevProps, prevState) {
// Typical usage (don't forget to compare props):
if (this.props.userID !== prevProps.userID) {
this.fetchData(this.props.userID);
}
}
componentWillUnmount() {
clearInterval(this.timerID);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment