-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@connect + contextType breaks with React 16.6 #1067
Comments
This is likely due to one of the known bugs in React where mixing legacy context and If there's an easy fix, we can potentially look at it, but otherwise my advice is to avoid using |
Can confirm using the decorator is not related here. |
Until react-redux v6 is released the easiest workaround is to wrap component with contextType into function component
|
Yeah, the The fix has been merged upstream and is released in |
The package-lock.json files aren't provided in npm packages, nor are they used when installing. So, as long as another dependency isn't blocking the upgrade, you can use that version with react-redux. |
Looks like Tim, can we get that into a 5.1.1 along with the edit derp, I should read things more carefully. Someone said 3.1.0 already @timdorr , we have a direct dep on |
Adding this to 5.1.1 |
Any news? Using redux and connect a parent component to it, the static contextType does not work for me either: |
@epavan : Please provide a project that specifically demonstrates this problem. |
Can't access this.context.object at all! Tried also the nonstatic version.
|
@epavan : can you please turn that into a CodeSandbox project that's runnable? |
I'm doubtful with some incompatibility with react-router 3 which uses context to provide router/route params. I'll try to codesandbox it. |
(I can provide a reproducible example if there's a simple test project that I can base it on.)
Essentially, I'm using React 16.6 and doing this:
And it fails with an error. In my concrete example, the value isn't
"world"
of course, but it happens to beundefined
, so I'm getting aTypeError: cannot read property 'store' of undefined
here becausecontext===undefined
. I guess if I were to pass"world"
as the context, it would instead fail theinvariant
just below.The problem is that the
<Connect(MyComponent)>
component gets its context populated based on mystatic contextType
, even though it's setting its own legacy context for the usual redux plumbing. But the new context takes precedence. This happens because<Connect(MyComponent)>
declares the legacycontextTypes
and additionally hoists thecontextType
from the nested component. This is ultimately a bug in thehoist-non-react-statics
library and I have already sent a fix there: mridgway/hoist-non-react-statics#62Please let me know if you disagree with the fix. In case they don't merge it soon,
react-redux
could work around the issue by doing something like this (I can send a PR):The text was updated successfully, but these errors were encountered: