Skip to content

Instantly share code, notes, and snippets.

@ramesaliyev
Created March 29, 2017 10:41
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 ramesaliyev/54ee3d71dfa2cea16bddb8ae02d159d1 to your computer and use it in GitHub Desktop.
Save ramesaliyev/54ee3d71dfa2cea16bddb8ae02d159d1 to your computer and use it in GitHub Desktop.
React.js Lifecycle Events
// Invoked once before first render
componentWillMount() {
console.log('componentWillMount');
// Calling setState here does not cause a re-render
}
// Invoked once after the first render
componentDidMount(){
console.log('componentDidMount');
}
// Invoked whenever there is a prop change
// Called BEFORE render
componentWillReceiveProps() {
console.log('componentWillReceiveProps');
// Not called for the initial render
// Previous props can be accessed by this.props
// Calling setState here does not trigger an an additional re-render
}
// Determines if the render method should run in the subsequent step
// Called BEFORE a render
// Not called for the initial render
shouldComponentUpdate() {
console.log('shouldComponentUpdate');
// If you want the render method to execute in the next step
// return true, else return false
return true;
}
// Called IMMEDIATELY BEFORE a render
componentWillUpdate() {
console.log('componentWillUpdate');
// You cannot use this.setState() in this method
}
// Called IMMEDIATELY AFTER a render
componentDidUpdate() {
console.log('componentDidUpdate');
}
// Called IMMEDIATELY before a component is unmounted
componentWillUnmount() {
console.log('componentWillUnmount');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment