React Core & Hooks (407 Qs)•Part 9: React Hooks Deep Dive (262 - 316)
What is the purpose of getSnapshotBeforeUpdate() lifecycle method?
junior LevelCode ExampleHooksLifecycle
The new getSnapshotBeforeUpdate() lifecycle method is called right before DOM updates. The return value from this method will be passed as the third parameter to componentDidUpdate().
javascript
class MyComponent extends React.Component {
getSnapshotBeforeUpdate(prevProps, prevState) {
// ...
}
}
scss
This lifecycle method along with `componentDidUpdate()` covers all the use cases of `componentWillUpdate()`.