Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chentsulin
Created November 5, 2018 14:34
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 chentsulin/9917890eda384589c87dfa8e8b34f8c6 to your computer and use it in GitHub Desktop.
Save chentsulin/9917890eda384589c87dfa8e8b34f8c6 to your computer and use it in GitHub Desktop.
Lifecycle
class App extends Component {
componentDidMount() {
this.subscribe(this.props.userId);
}
componentDidUpdate(prevProps) {
if (this.props.userId !== prevProps.userId) {
this.unsubscribe(this.props.userId);
this.subscribe(this.props.userId);
}
}
componentWillUnmount() {
this.unsubscribe(this.props.userId);
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment