getSnapshotBeforeUpdate
The getSnapshotBeforeUpdate method is part of the React component lifecycle and is invoked just before the DOM updates are applied. It receives the previous props and state as arguments and should return a snapshot value that React will pass as the third argument to componentDidUpdate. This snapshot is typically used to preserve information from the DOM that must be retained across a re-render, such as scroll positions, measurements or any other transient state derived from the current DOM.
A typical pattern involves measuring elements in getSnapshotBeforeUpdate and then using the snapshot in componentDidUpdate to
React guarantees that getSnapshotBeforeUpdate is only called for components that implement it, and it is only
This method was introduced to replace former techniques that relied on componentDidUpdate alone for handling scroll