React-redux: Fix <StrictMode> warnings

Created on 8 Mar 2018  路  35Comments  路  Source: reduxjs/react-redux

Is it possible to replace componentWillReceiveProps because is deprecated to remove React 16+ warning.

Most helpful comment

Yes, the purpose of 16.3 was to let libraries start migrating before the deprecation warnings.

All 35 comments

cWRP isn't deprecated until React 16.4. As of this moment, 16.3 isn't even out. We're looking at larger refactors around async stuff in React 17 in #890.

cWRP seems to be depreacted.

screenshot_1520587667

@BenoitClaveau Which version of react do you use? It shouldn't happen until 16.4.

This started showing up after updating to react-native 0.54.0.

downgrading to react 16.2.0 doesn't remove the warnings

I guess the problem is react-native. AFAIK they published package with react alpha which had this problem. Try to downgrade it.

under "react": "16.2.0",

The warnings are coming from react-native so downgrading react isn't enough. react-native 0.53 with react 16.2.0 doesn't have the warnings

Yes, I meant downgrade react-native.

Downgrading shouldn't be the option, since the latest valid version of react-native does deprecated these functions. Is there a ETA on the change?

getDerivedStateFromProps is easy enough using the react-lifecycles-compat thing which isn't a breaking change.
And context also has a non-breaking polyfill (though only for React 16 which would be a breaking change):
https://github.com/thejameskyle/create-react-context

@timdorr I would like to make a PR migrating react-redux to new lifecycles using react-lifecycles-compat because I don't want StrictMode to warn me about my Connected components. Does it make sense to you?

I'm surprised I have to mention it on this repo, but this React blogpost says that library authors don't have to wait until actual deprecation happens
https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html

The primary purpose of the upcoming version 16.3 release is to enable open source project maintainers to update their libraries in advance of any deprecation warnings.

Yes, the purpose of 16.3 was to let libraries start migrating before the deprecation warnings.

@gaearon I also think it would make a lot of sense for you to include a link to create-react-context polyfill same as you did for react-lifecycles-compat because otherwise people don't even know that they can transition their libraries to the new context without breaking React 16 users (though breaking all older Reacts).
Specifically I had to google a lot until I accidentally came across that create-react-context polyfill thing. It would make life easier for a lot of component mainterners if you included that link as a sidenote in the announcement blog post.

UPD: Oh, actually, it was not you, it was "Brian Vaughn", ok.

Updating the title to better reflect what this is about. I'll put up a failing PR in a sec that others can build off of.

Edit: Looks like we're on React 15 still. I'm updating things to Jest and then React 16. And then I'll get to this. Bikeshedding at maximum speed!

OK, phew, got all that done. We're now on React 16, Jest, and react-test-renderer.

Here's a failing test: #918

@catamphetamine Looks like create-react-context can actually be used to support React 15 and below. One should just be carefull and always pass a singe child element to Provider and always return a single element from Consumer child function. See jamiebuilds/create-react-context#15

@Hypnosphi Yeah... create-react-context _only_ polyfills React.createContext you are still limited to the rendering features of the versions of React you are compatible with.

has this fix been released? which version?
I'm using:

"react": "^16.3.2",
"react-redux": "^5.0.6",

and still getting the error in strict-mode.

For example:

componentWillReceiveProps: Please update the following components to use static getDerivedStateFromProps instead: Connect(ProfileHandlerHoc)

componentWillUpdate: Please update the following components to use componentDidUpdate instead: Connect(ProfileHandlerHoc)

@packetstracer https://github.com/reactjs/react-redux/pull/919 isn't merged yet

@packetstracer : please update to React-Redux 5.0.7 first, and see if that fixes the issue for you.

i've updated to react-redux 5.0.7 and also getting the same warnings as @packetstracer

still throwing these errors after update

componentWillReceiveProps: Please update the following components to use static getDerivedStateFromProps instead: Connect(DemoSideBarNavContainer), Connect(LanguageSelectorContainer), Connect(ProfileHandlerHoc)

componentWillUpdate: Please update the following components to use componentDidUpdate instead: Connect(DemoSideBarNavContainer), Connect(LanguageSelectorContainer), Connect(ProfileHandlerHoc)

package.json content
"react-redux": "^5.0.7",

cat node_modules/react-redux/package.json

{
  "name": "react-redux",
  "version": "5.0.7",
  "description": "Official React bindings for Redux",

Any clue on what could be?

Those aren't fixed in 5.0.7. We have an outstanding PR to fix them.

So what is the alternative to use until the PR was merged to fix the warnings?

@slim-hmidi are you building a library or an app? If the latter, you shouldn't need StrictMode for now

@Hypnosphi I'm building an application.

Hey folks, any update on the PR being merged? Thanks!

Anyone coming here with this problem, you can use react-redux@next with npm (resolved to 5.1.0-test.1 as of now).

Can this issue be reopened, since the commit that fixed it was reverted in 73691e5?

Sure. Though either #995 or #1000 is going to solve it.

Now that #1000 was merged, please make sure it works with StrictMode as well before releasing! 馃檶 cc @timdorr @markerikson

Tbh, I haven't tried that part out yet myself... but go install react-redux@next and let us know!

Purely off the top of my head, it _ought_ to be just fine. We no longer use cWRP or cWU at all.

Just tested 6.0.0-beta.2, it did fix the warnings! :) thanks.

_Now it's just react-native left :P https://github.com/facebook/react-native/issues/22186_

Clooooosing out!

Was this page helpful?
0 / 5 - 0 ratings