0 votes
in ReactJS by
What is the purpose of getSnapshotBeforeUpdate() lifecycle method?

1 Answer

0 votes
by

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().

class MyComponent extends React.Component {

  getSnapshotBeforeUpdate(prevProps, prevState) {

    // ...

  }

}

This lifecycle method along with componentDidUpdate() covers all the use cases of componentWillUpdate().

Related questions

0 votes
asked Jul 2, 2019 in ReactJS by Venkatshastri
0 votes
asked Nov 26, 2019 in ReactJS by AdilsonLima
...