Handling componentWillReceiveProps deprecation in React >= 17
See original GitHub issueThe docs currently reference componentWillReceiveProps
as the recommended way to listen to route changes when using shallow routing:
You can watch for URL changes via componentWillReceiveProps hook as shown below:
componentWillReceiveProps(nextProps) {
const { pathname, query } = nextProps.url
// fetch data based on the new query
}
This lifecycle, however, is on the deprecation path; it will stop working as-named in React 17: https://reactjs.org/docs/react-component.html#unsafe_componentwillreceiveprops
Given that, we should provide a more future-friendly solution for listening for shallow route changes. Perhaps adding a popstate
listener in componentDidMount
. If that seems like the best option I can add it to docs, but opening this ticket for discussion/tracking.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
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 >Handle 'componentWillReceiveProps' deprecation warning
As part of the implementation of async rendering in React, there are a few lifecycle methods which will be deprecated in React 17...
Read more >React 17 lifecycle - Medium
The React team has decided to deprecate some of the lifecycle methods with React 17 ... It's main job is replacing componentWillReceiveProps.
Read more >React.Component
In the event of an error, you can render a fallback UI with componentDidCatch() by calling setState , but this will be deprecated...
Read more >Refactor componentWillReceiveProps() to ... - Egghead.io
The componentWillReceiveProps() method is being deprecated in future version of React (17). Many of us use this method day-to-day to check for incoming...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Related to react-hot-loader. We have to update to rhl 5.1 for it to work correctly, but I want to do some testing first
react-hot-loader
is also usingcomponentWillReceiveProps
inAppContainer
right now btw.