...

/

Method 2: getSnapshotBeforeUpdate

Method 2: getSnapshotBeforeUpdate

Let's discuss the "getSnapshotBeforeUpdate" method which stores the previous version of the application before uploading the changes.

In the updating component phase, the getSnapshotBeforeUpdate lifecycle method is called right after the render method.

Understanding the Mechanism

This one is a little tricky, but I’ll take my time explaining how it works.

Chances are you won’t always reach for this lifecycle method, but it may come in handy in certain cases. Specifically, when you need to grab some information from the DOM (and potentially change it) just after an update is made.

Here’s the important thing. The value queried from the DOM in getSnapshotBeforeUpdate will refer to the value just before the DOM is updated, even though the render method was ...