So Dan Abramov answered on Twitter and it seems like there are 2 reasons why you should use getDerivedStateFromProps instead of componentDidUpdate + setState:

setState in componentDidUpdate causes an extra render (not directly perceptible to user but it slows down your app). And your render method can’t assume the state is ready (because it won’t be the first time).

  • Performance reason: it avoids unnecessary re-render.
  • As getDerivedStateFromProps is called before rendering on init, you can initialise your state in this function instead of having a constructor to do so. Currently you had to have a constructor or componentWillMount to init your state before initial rendering.
Answer from adriendenat on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 63351774 › getderivedstatefromprops-vs-componentdidupdate
react native - getDerivedStateFromProps() vs componentDidUpdate() - Stack Overflow
But some people are highly recommending not to use this method, Instead suggesting to use componentDidUpdate. But for my requirement all new props must be set with the state before render. getDerivedStateFromProps is the best place to do so.
🌐
React
legacy.reactjs.org › docs › react-component.html
React.Component – React
If you need to perform a side effect (for example, data fetching or an animation) in response to a change in props, use componentDidUpdate lifecycle instead. If you want to re-compute some data only when a prop changes, use a memoization helper ...
Discussions

How to use lifecycle method getDerivedStateFromProps as opposed to componentWillReceiveProps
About the removal of componentWillReceiveProps: you should be able to handle its uses with a combination of getDerivedStateFromProps and componentDidUpdate, see the React blog post for example migrations. More on stackoverflow.com
🌐 stackoverflow.com
Why use getDerivedStateFromProps when you have componentDidUpdate?
I'm confused about the new lifecycle of react 16, getDerivedStateFromProps use case. Take below code for example, getDerivedStateFromProps is not needed at all since I can achieve what I want with componentDidUpdate. More on stackoverflow.com
🌐 stackoverflow.com
April 27, 2018
Newest 'getderivedstatefromprops' Questions - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers More on stackoverflow.com
🌐 stackoverflow.com
componentWillReceiveProps vs getDerivedStateFromProps
If you need to perform a side effect ... use componentDidUpdate lifecycle instead. If you want to re-compute some data only when a prop changes, use a memoization helper instead. If you want to “reset” some state when a prop changes, consider either making a component fully controlled or fully uncontrolled with a key instead. P.S. Note that the arguments to getDerivedStateFromProps are props ... More on stackoverflow.com
🌐 stackoverflow.com
People also ask

Is componentDidUpdate deprecated?
No, componentDidUpdate is not deprecated. It remains a recommended lifecycle method in class-based React components for handling prop changes, state updates, and side effects like data fetching. Unlike componentWillReceiveProps, which is deprecated, componentDidUpdate ensures updates occur after rendering, making it safer for managing component updates efficiently.
🌐
dhiwise.com
dhiwise.com › blog › design-converter › componentwillreceiveprops-vs-componentdidupdate-in-react
ComponentWillReceiveProps vs. ComponentDidUpdate: Which to Use ...
What is the difference between componentDidUpdate and componentDidMount?
componentDidUpdate runs after every re-render caused by prop or state updates, making it ideal for handling prop changes, data fetching, and DOM updates. In contrast, componentDidMount runs only once after the initial render, often used for initial data fetching, setting up subscriptions, or manipulating DOM nodes when the component instance is first mounted.
🌐
dhiwise.com
dhiwise.com › blog › design-converter › componentwillreceiveprops-vs-componentdidupdate-in-react
ComponentWillReceiveProps vs. ComponentDidUpdate: Which to Use ...
What to use instead of componentWillReceiveProps?
Instead of componentWillReceiveProps, use componentDidUpdate for handling prop changes or getDerivedStateFromProps if state values need to be derived from new props. In functional components, use the useEffect hook with dependencies to handle updates reactively.
🌐
dhiwise.com
dhiwise.com › blog › design-converter › componentwillreceiveprops-vs-componentdidupdate-in-react
ComponentWillReceiveProps vs. ComponentDidUpdate: Which to Use ...
Top answer
1 of 2
37

So Dan Abramov answered on Twitter and it seems like there are 2 reasons why you should use getDerivedStateFromProps instead of componentDidUpdate + setState:

setState in componentDidUpdate causes an extra render (not directly perceptible to user but it slows down your app). And your render method can’t assume the state is ready (because it won’t be the first time).

  • Performance reason: it avoids unnecessary re-render.
  • As getDerivedStateFromProps is called before rendering on init, you can initialise your state in this function instead of having a constructor to do so. Currently you had to have a constructor or componentWillMount to init your state before initial rendering.
2 of 2
2

getDerivedStateFromProps is actually replacement for componentWillReceiveProps and componentDidMount is not going to be deprecated.

I'm pretty sure it was the community that decided to make a static method with that name.

The reason for this change is that componentWillReceiveProps was one of the methods that led to confusion and further to some memory leaks in user applications:

Many of these issues are exacerbated by a subset of the component lifecycles (componentWillMount, componentWillReceiveProps, and componentWillUpdate). These also happen to be the lifecycles that cause the most confusion within the React community. For these reasons, we are going to deprecate those methods in favor of better alternatives.

Here's the Dan Abramov tweet that also makes this more clear:

However, this means that we’ll part our ways with componentWillReceiveProps() in 17. We think getDerivedStateFromProps() does the same job better and is less confusing. It also happens that cWRP() really messes up our plans for data fetching features that might be in pipeline.

🌐
React
react.dev › reference › react › Component
Component – React
If you need to perform a side effect (for example, data fetching or an animation) in response to a change in props, use componentDidUpdate method instead. If you want to re-compute some data only when a prop changes, use a memoization helper instead.
🌐
DhiWise
dhiwise.com › blog › design-converter › componentwillreceiveprops-vs-componentdidupdate-in-react
ComponentWillReceiveProps vs. ComponentDidUpdate: Which to Use in React?
March 5, 2025 - Unlike componentDidUpdate, this method does not have access to this, making it useful for extracting pure functions when updating state from props change: ... 1class ExampleComponent extends React.Component { 2 constructor(props) { 3 super(props); ...
🌐
Medium
medium.com › swlh › lifecycle-state-and-getderivedstatefromprops-761b3a19c4e
Lifecycle, state, getDerivedStateFromProps and Hooks | by Thomas Rubattel | The Startup | Medium | The Startup
December 17, 2022 - Replace componentWillReceiveProps by getDerivedStateFromProps which also needs to be pure, or by React Hooks. If possible do not use getDerivedStateFromProps at all. componentDidMount and componentDidUpdate are the only lifecycle functions where you might put side-effect in, for example Ajax call, local storage access, DOM access.
Find elsewhere
Top answer
1 of 4
119

About the removal of componentWillReceiveProps: you should be able to handle its uses with a combination of getDerivedStateFromProps and componentDidUpdate, see the React blog post for example migrations. And yes, the object returned by getDerivedStateFromProps updates the state similarly to an object passed to setState.

In case you really need the old value of a prop, you can always cache it in your state with something like this:

state = {
  cachedSomeProp: null
  // ... rest of initial state
};

static getDerivedStateFromProps(nextProps, prevState) {
  // do things with nextProps.someProp and prevState.cachedSomeProp
  return {
    cachedSomeProp: nextProps.someProp,
    // ... other derived state properties
  };
}

Anything that doesn't affect the state can be put in componentDidUpdate, and there's even a getSnapshotBeforeUpdate for very low-level stuff.

UPDATE: To get a feel for the new (and old) lifecycle methods, the react-lifecycle-visualizer package may be helpful.

2 of 4
63

As we recently posted on the React blog, in the vast majority of cases you don't need getDerivedStateFromProps at all.

If you just want to compute some derived data, either:

  1. Do it right inside render
  2. Or, if re-calculating it is expensive, use a memoization helper like memoize-one.

Here's the simplest "after" example:

import memoize from "memoize-one";

class ExampleComponent extends React.Component {
  getDerivedData = memoize(computeDerivedState);

  render() {
    const derivedData = this.getDerivedData(this.props.someValue);
    // ...
  }
}

Check out this section of the blog post to learn more.

🌐
DigitalOcean
digitalocean.com › community › tutorials › react-get-derived-state
Using Derived State in React | DigitalOcean
July 1, 2018 - getDerivedStateFromProps may be called multiple times for a single update, so it’s important to avoid any side-effects. Instead, you should use componentDidUpdate, which executes only once after the component updates.
🌐
Rheinwerk Computing
blog.rheinwerk-computing.com › the-component-lifecycle-in-react
The Component Lifecycle in React
March 19, 2025 - The getDerivedStateFromProps and shouldComponentUpdate methods are still called every second. The getSnapshotBeforeUpdate method enables you to implement a hook that is executed after the render method has been run and before the changes are displayed. In this method, you have access to the previous state and props. The return value of this method must be either null or a value. This is then available in the componentDidUpdate ...
🌐
DhiWise
dhiwise.com › post › best-practices-for-using-getderivedstatefromprops-in-your-react-applications
The Role of getDerivedStateFromProps in the React
October 27, 2023 - Second, getDerivedStateFromProps is called both before the initial render and before every update. This is different from other lifecycle methods like componentDidMount and componentDidUpdate, which are only called once after the first render ...
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › what-are-the-alternatives-to-componentwillreceiveprops-in-react
What Are The Alternatives To componentWillReceiveProps In React? - GeeksforGeeks
July 23, 2025 - This article will explore the recommended alternatives: getDerivedStateFromProps, componentDidUpdate, and hooks like useEffect.
Top answer
1 of 3
26

From this article:

As componentWillReceiveProps gets removed, we need some means of updating the state based on props change — the community decided to introduce a new — static — method to handle this.

What’s a static method? A static method is a method / function that exists on the class not its instance. The easiest difference to think about is that static method does not have access to this and has the keyword static in front of it.

Ok, but if the function has no access to this how are we to call this.setState? The answer is — we don’t. Instead the function should return the updated state data, or null if no update is needed

The returned value behaves similarly to current setState value — you only need to return the part of state that changes, all other values will be preserved.

You still need to declare the initial state of the component (either in constructor or as a class field).

getDerivedStateFromProps is called both on initial mounting and on re-rendering of the component, so you can use it instead of creating state based on props in constructor.

If you declare both getDerivedStateFromProps and componentWillReceiveProps only getDerivedStateFromProps will be called, and you will see a warning in the console.

Usually, you would use a callback to make sure some code is called when the state was actually updated — in this case, please use componentDidUpdate instead.

2 of 3
0

With componentDidUpdate you can execute callbacks and other code that depends on the state being updated.

getDerivedStateFromProps is a static function and so has no access to the this keyword. Also you wouldn't have any callbacks placed here as this is not an instance based lifecycle method. Additionally triggering state changes from here could cause loops(e.g. with redux calls).

They both serve different fundamental purposes. If it helps getDerivedStateFromProps is replacing componentWillReceiveProps.

🌐
HackerNoon
hackernoon.com › replacing-componentwillreceiveprops-with-getderivedstatefromprops-c3956f7ce607
Replacing ‘componentWillReceiveProps’ with ‘getDerivedStateFromProps’ | HackerNoon
May 13, 2018 - With the release of React 16.3, some new lifecycle methods have been introduced, and release of React 17 will deprecate some lifecycle method.
🌐
Irigoyen
irigoyen.dev › blog › 2021 › 04 › 07 › converting-react-class-component-lifecycle-methods-to-hooks
Converting React Class Component Lifecycle Methods to Hooks by Michael Irigoyen
April 7, 2021 - While it is unlikely that you will need it, you can simply update the state during render. React will run the component again immediately after the first render with the updated state. While this may seem like the wrong way to handle this, an update during rendering is how getDerivedStateFromProps has always worked under the hood.
🌐
Stack Overflow
stackoverflow.com › questions › tagged › getderivedstatefromprops
Newest 'getderivedstatefromprops' Questions - Stack Overflow
I like to update my code to use getDerivedStateFromProps instead of componentWillReceiveProps as the I am receiving deprecated error.
Top answer
1 of 3
7

getDerivedStateFromProps is not a direct alternative to componentWillReceiveProps, purely because of the fact that its called after every update, whether its the change in state or change in props or re-render of parent.

However whatever is the case, simply returning the state from getDerivedStateFromProps is not the right way, you need to compare the state and props before returning the value. Else with every update the state is getting reset to props and the cycle continues

As per the docs

getDerivedStateFromProps is invoked right before calling the render method, both on the initial mount and on subsequent updates. It should return an object to update the state, or null to update nothing.

This method exists for rare use cases where the state depends on changes in props over time. For example, it might be handy for implementing a <Transition> component that compares its previous and next children to decide which of them to animate in and out.

Deriving state leads to verbose code and makes your components difficult to think about. Make sure you’re familiar with simpler alternatives:

If you need to perform a side effect (for example, data fetching or an animation) in response to a change in props, use componentDidUpdate lifecycle instead.

If you want to re-compute some data only when a prop changes, use a memoization helper instead.

If you want to “reset” some state when a prop changes, consider either making a component fully controlled or fully uncontrolled with a key instead.

P.S. Note that the arguments to getDerivedStateFromProps are props and state and not nextProps and prevProps

To get into more details,

In order to make changes based on props change, we need to store prevPropsState in state, in order to detect changes. A typical implementation would look like

static getDerivedStateFromProps(props, state) {
    // Note we need to store prevPropsState to detect changes.
    if (
      props.myPropsState !== state.prevPropsState
    ) {
      return {
        prevPropsState: state.myState,
        myState: props.myPropsState
      };
    }
    return null;
  }
2 of 3
1

Finally, I resolved my issue. It was a painful debugging:

// Child Component

// instead of this
// this.props.onMyDisptach([...myPropsState])

// dispatching true value since myPropsState contains only numbers
this.props.onMyDispatch([...myPropsState, true])

This is because, I have two conditions: 1) on checkbox change (component) 2) on reset button pressed (child component)

I was needing to reset the states when reset button is pressed. So, while dispatching state to the props for reset button, I used a boolean value to know it's a change from the reset. You may use anything you like but need to track that.

Now, here in the component, I found some hints to the differences between componentWillReceiveProps and getDerivedStateFromProps after debugging the console output.

// Component
static getDerivedStateFromProps(props, state) {
    const { myPropsState: myState } = props
    // if reset button is pressed
    const true_myState = myState.some(id=>id===true)
    // need to remove true value in the store
    const filtered_myState = myState.filter(id=>id!==true)
    if(true_myState) {
      // we need to dispatch the changes to apply on its child component
      // before we return the correct state
      props.onMyDispatch([...filtered_myState])
      return {
        myState: filtered_myState
      }
    }
    // obviously, we need to return null if no condition matches
    return null
  }

Here's what I found the results of the console output:

  • getDerivedStateFromProps logs immediately whenever props changes

  • componentWillReceiveProps logs only after child propagates props changes

  • getDerivedStateFromProps doesn't respond to the props changes ( I meant for the dispatch changes as in the example code)

  • componentWillReceiveProps responds to the props changes

  • Thus, we needed to supply the changes to child component while using getDerivedStateFromProps.

The process of pasting true value in the state I require because getDerivedStateFromProps handle all the changes unlike componentWillReceiveProps handles only the child component dispatches the changes to the props.

By the way, you may use custom property to check if it is changed and update the value if getDerivedStateFromProps but for some reason I have to tweak this technique.

There might be some confusion on my wording but I hope you'll get it.

🌐
W3Schools
w3schools.com › react › react_class.asp
React Class Components
getDerivedStateFromProps() shouldComponentUpdate() render() getSnapshotBeforeUpdate() componentDidUpdate() The render() method is required and will always be called, the others are optional and will be called if you define them. Also at updates the getDerivedStateFromProps method is called.
🌐
Larry-price
larry-price.com › blog › 2018 › 06 › 27 › how-to-use-getderivedstatefromprops-in-react-16-dot-3-plus
How to Use getDerivedStateFromProps in React 16.3+ - Larry Price
componentDidUpdate is similar to componentDidMount except that is caused after a change in state or props occurs instead of just on initial mount. As opposed to getDerivedStateFromProps, we have access to the context provided by this.