-
-
Save b17z/c7dbc676d17ac7c7de6bbfb523a79b39 to your computer and use it in GitHub Desktop.
React component 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
class Component extends React.Component { | |
static getDerivedStateFromProps (nextProps, prevState) { | |
// -> nextState | |
// | Called after instantiating and when it receives new props | |
} | |
render () { | |
// -> jsx | |
} | |
componentDidMount () { | |
// | Called just after mounting, handy for calling the network and setting up subscriptions | |
// | setState will trigger rendering before the DOM is updated | |
} | |
shouldComponentUpdate(nextProps, nextState) { | |
// -> shouldUpdate | |
// | Checks whether the component should update. | |
} | |
getSnapshotsBeforeUpdate () { | |
// Invoked before rendering output to the DOM | |
// Used to mitigate any sideeffects caused by an update | |
// Result will be passed to `componentDidUpdate` | |
} | |
componentDidUpdate (prevProps, prevState, snapshot) { | |
// Invoked after updateing | |
// Not called for initial render | |
} | |
componentWillUnmount () { | |
// Called before the component unmounts | |
// Remove timers, subscriptions, cancel network calls, etc. | |
} | |
componentDidCatch (error, info) { | |
// Error boundaries for the component. | |
// Handy for catching errors during rendering, in lifecycle methods. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment