What is the purpose of getDerivedStateFromProps() lifecycle method?
- To fetch data from an API
- To handle events
- To update the props based on state changes
- To update the state based on props changes
The "getDerivedStateFromProps" lifecycle method in React is used to update the state based on changes to props. This method is called every time the component is updated and can return a new state object. It is commonly used to synchronize the state with the props in response to user input or server-side changes.
Loading...