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

1 Answer

0 votes
by

The new static getDerivedStateFromProps() lifecycle method is invoked after a component is instantiated as well as before it is re-rendered. It can return an object to update state, or null to indicate that the new props do not require any state updates.

class MyComponent extends React.Component {

  static getDerivedStateFromProps(props, state) {

    // ...

  }

}

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

Related questions

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