November 2018
Beginner
502 pages
10h 22m
English
getSnapshotBeforeUpdate is called just before the DOM is updated. The value that is returned from getSnapshotBeforeUpdate is passed on to componentDidUpdate.
componentDidUpdate is called as soon as the DOM is updated. Resizing the window during rendering is an example of when getSnapshotBeforeUpdate can be useful.
Let's have a look at these life cycle methods in our app:
private renderCount = 0;
public getSnapshotBeforeUpdate(prevProps: {}, prevState: IState) { this.renderCount += 1; console.log("getSnapshotBeforeUpdate", prevProps, prevState, { renderCount: ...Read now
Unlock full access