garrettmac
8/25/2017 - 4:42 PM

react-lifecycle-cheatsheet.md

Lifecycle (in order)Triggered WhenUse When
getDefaultPropsTriggered whenUseful when
The result of getDefaultProps() will be cached and used to ensure that this.props.value will have a value if it was not specified by the parent component.
componentWillMount()Triggered before render().Useful when
componentDidMount()Triggered Called after render. Can access refs. The componentDidMount() method of child components is invoked before that of parent components. This is the place to call external libraries, use setTimeout, make ajax requestsUseful when
shouldComponentUpdate(nextProps, nextState)Triggered when updatesUseful when called when there are new props or state changes. return false to prevent a render. good for performance.
componentWillReceiveProps(nextProps)Triggered when view is updatedUseful when Called before render when props change. Access to old props. It is not triggered after the component is mounted.
componentWillUpdate(nextProps, nextState)Triggered when immediately before rendering when new props or state are being received. Not called for the initial render. Cannot use setState in this method. Use componentWillReceiveProps instead. Use this as an opportunity to perform preparation before an update occurs.Useful when
renderTriggered when the state changes.Useful when
componentDidUpdate(prevState, prevProps)Triggered when updatesUseful when you want to access to prevState, prevProps Use this as an opportunity to operate on the DOM when the component has been updated.
componentWillUnmountTriggered whenUseful to clean up event bindings, etc.