What is the purpose of getDerivedStateFromProps() lifecycle method in react.js?

Answer

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

All react js Questions

Ask your interview questions on react-js

Write Your comment or Questions if you want the answers on react-js from react-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---