question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migrate from react UNSAFE_componentWillReceiveProps to getDerivedStateFromProps

See original GitHub issue

Describe the issue We current use in the Graph component the react lifecycle method componentWillReiceveProps. This method has been deprecated in favor of getDerivedStateFromProps(props, state).

Expected Refactor UNSAFE_componentWillReceiveProps into getDerivedStateFromProps.

Environment: All.

Additional context Consider that no fundamental changes should be made in the current implementation of UNSAFE_componentWillReceiveProps, we only want to migrate the react bits in order to keep the library compliant with the newest versions of react.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AngelsProjectscommented, Oct 17, 2019

can I take it? it’s really simple… it already took too much time of this issue

0reactions
danielcaldascommented, Mar 1, 2020

This issue is still ongoing, it happens that the migration is not that trivial due to the flow of execution change of getDerivedStateFromProps which gets executed at every render…

From react docs:

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating From Unsafe React Lifecycle Hooks.
The new static getDerivedStateFromProps lifecycle is invoked right before calling the render method, both on the initial mount and on subsequent ...
Read more >
React17, or how to get rid of “componentWillReceiveProps”?
It should return an object to update the state, or null to update nothing. This method is useful only for state handling, and...
Read more >
React.Component
constructor(); static getDerivedStateFromProps(); render(); componentDidMount() ... UNSAFE_componentWillUpdate(); UNSAFE_componentWillReceiveProps() ...
Read more >
ReactJS UNSAFE_componentWillReceiveProps() Method
The componentWillReceiveProps() method has been deprecated in the latest releases of React as per this issue. It is recommended to use ...
Read more >
Replacing 'componentWillReceiveProps' with ' ...
With the release of React 16.3, some new lifecycle methods have ... static getDerivedStateFromProps(nextProps, prevState){ if(nextProps.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found