Created
March 29, 2017 10:41
-
-
Save ramesaliyev/54ee3d71dfa2cea16bddb8ae02d159d1 to your computer and use it in GitHub Desktop.
React.js Lifecycle Events
This file contains hidden or 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
// 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