Last active
January 24, 2020 14:37
-
-
Save FrankGerold/dc3a1fe6d435fab511ce0750aacdd62c to your computer and use it in GitHub Desktop.
React Lifecycle Methods
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
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