From react blog, 16.3 introduced deprecation notices for componentWillRecieveProps.
As a workaround, you would use the method
static getDerivedStateFromProps(nextProps, prevState)
therefore
componentWillReceiveProps(props){
let total = props.results.length;
let pass = props.results.filter(r => r.status == 'pass').length;
let fail = total - pass;
let passp = (pass/(total || 1) *100).toFixed(2);
let failp = (fail/(total || 1) *100).toFixed(2);
this.setState({total, pass, fail, passp, failp});
}
becomes
static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.total !== prevState.total) {
return ({ total: nextProps.total }) // <- this is setState equivalent
}
return null
}
Answer from Denis Tsoi on Stack OverflowGeeksforGeeks
geeksforgeeks.org › reactjs › what-are-the-alternatives-to-componentwillreceiveprops-in-react
What Are The Alternatives To componentWillReceiveProps In React? - GeeksforGeeks
July 23, 2025 - In React, componentWillReceiveProps is a lifecycle method that was deprecated in version 16.3 and subsequently removed in version 17. To handle similar logic, you can use alternative lifecycle methods and hooks that are recommended in modern React development.
DhiWise
dhiwise.com › post › how-does-componentwillreceiveprops-work-in-react
Mastering componentWillReceiveProps: Best Practices
November 21, 2024 - Additionally, componentWillReceiveProps can be skipped if the update is triggered by a state change, causing unexpected behavior. To avoid these pitfalls, it’s essential to use componentWillReceiveProps judiciously and consider alternative methods, such as getDerivedStateFromProps.
Replacement for componentWillReceiveProps and need guidance
Could you give some examples of what you're doing currently? More on reddit.com
Discussion: componentWillReceiveProps vs getDerivedStateFromProps
Hello We have found a scenario where the removal of componentWillReceiveProps will encourage us to write worse code than we currently do. We currently consider props to be a valid form of input and state for our component. If a component... More on github.com
reactjs - Alternative to componentWillReceiveProps for my particular use case - Stack Overflow
Since componentWillReceiveProps will be deprecated, I have heard alternatives to use componentDidUpdate, but the problem is componentDidUpdate will also be invoked on state changes as well. Now, most More on stackoverflow.com
reactjs - How to definitely replace componentWillReceiveProps and keep getting the nextProps? - Stack Overflow
I am running React 16.8.4 in my App and I really need to use nextProps in some cases. As React Docs mention, componentWillReceiveProps is an UNSAFE method an is not recommended to use it anymore. I... More on stackoverflow.com
Videos
Medium
medium.com › hackernoon › replacing-componentwillreceiveprops-with-getderivedstatefromprops-c3956f7ce607
Replacing ‘componentWillReceiveProps’ with ‘getDerivedStateFromProps’ | by Amanshu Kataria | HackerNoon.com | Medium
January 19, 2021 - In above code nextProps and prevState are compared, if both are different then an object will be returned to update the state otherwise null will be returned indicating state update not required. If state changes then componentDidUpdate is called where we can perform the desired operations as we did in componentWillReceiveProps.
Reddit
reddit.com › r/reactjs › replacement for componentwillreceiveprops and need guidance
r/reactjs on Reddit: Replacement for componentWillReceiveProps and need guidance
February 15, 2022 -
We have been using componentWillReceiveProps peacefully and then we decided to upgrade our application to v17 and we read to know to use static getDerivedStateFromProps and the usage of the function is not as same as earlier one and it is giving me more confusion on making the application as stable. Guide me please.
DigitalOcean
digitalocean.com › community › tutorials › react-get-derived-state
Using Derived State in React | DigitalOcean
July 1, 2018 - In React v16.3, the getDerivedStateFromProps static lifecycle method was introduced as a replacement for componentWillReceiveProps.
GitHub
github.com › reactjs › react.dev › issues › 721
Discussion: componentWillReceiveProps vs getDerivedStateFromProps · Issue #721 · reactjs/react.dev
March 28, 2018 - However, with the removal of componentWillReceiveProps, react will force us to use setState for any prop we would like to monitor for change.
Author arieh
React
legacy.reactjs.org › docs › react-component.html
React.Component – React
Note that this method is fired on every render, regardless of the cause. This is in contrast to UNSAFE_componentWillReceiveProps, which only fires when the parent causes a re-render and not as a result of a local setState.
DhiWise
dhiwise.com › blog › design-converter › componentwillreceiveprops-vs-componentdidupdate-in-react
ComponentWillReceiveProps vs. ComponentDidUpdate: Which to Use in React?
March 5, 2025 - Understanding the Component LifecyclecomponentWillReceiveProps: What It DoescomponentDidUpdate: The Modern AlternativeComparing componentWillReceiveProps and componentDidUpdateWrapping Up: Writing Better React Code
React
legacy.reactjs.org › blog › 2018 › 06 › 07 › you-probably-dont-need-derived-state.html
You Probably Don't Need Derived State – React Blog
June 7, 2018 - Even though the example above shows getDerivedStateFromProps, the same technique can be used with componentWillReceiveProps. More rarely, you may need to reset state even if there’s no appropriate ID to use as key. One solution is to reset the key to a random value or autoincrementing number each time you want to reset. One other viable alternative is to expose an instance method to imperatively reset the internal state:
egghead.io
egghead.io › lessons › react-refactor-componentwillreceiveprops-to-getderivedstatefromprops-in-react-16-3
Refactor componentWillReceiveProps() to getDerivedStateFromProps() in React 16.3 | egghead.io
[01:24] I set Computed Message to null and componentWillReceiveProps to display the loader until the value returns. To refactor this component away from componentWillReceiveProps, I'll have to split its functionality into two lifecycle methods.
Published April 19, 2018
Top answer 1 of 2
6
this.props in componentDidUpdate will be the same as nextProps in componentWillReceiveProps, so you could use that.
// componentWillReceiveProps(nextProps) {
// if (nextProps.someProp !== this.props.someProp) {
// doSomething();
// }
// }
componentDidUpdate(prevProps) {
if (this.props.someProp !== prevProps.someProp) {
doSomething();
}
}
2 of 2
1
You can use getDerivedStateFromProps instead of componentWillReceiveProps.
Medium
medium.com › @yassimortensen › react-component-lifecycle-methods-part-ii-c25abac7c693
React Component lifecycle methods, part II | by Yassi Mortensen | Medium
March 24, 2018 - In cases where shouldComponentUpdate is implemented, this function can be used instead of componentWillReceiveProps. But, in my opinion, I would still with componentWillReceiveProps whenever possible. It’s a lot cleaner, and the naming of the components make it less confusing and easier to debug.
React
react.dev › reference › react › Component
Component – React
Calling setState inside UNSAFE_componentWillReceiveProps in a class component to “adjust” state is equivalent to calling the set function from useState during rendering in a function component. If you define UNSAFE_componentWillUpdate, React will call it before rendering with the new props or state. It only exists for historical reasons and should not be used in any new code. Instead, use one of the alternatives: