What is the purpose of getDerivedStateFromProps() lifecycle method?

Posted by Prem Tiwari | Updated on

What is the purpose of getDerivedStateFromProps() lifecycle method?

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.

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


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers