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
Unexpected usage of context
prop on connected component
#1139
Comments
Based on my understanding, v6 allows you to provide a custom context, in which case React-Redux will use your provided context instead of its default one. This allows you to use your own context consumer in your connected components. You need to pass the same context to both const MyContext = React.createContext();
// provide to the Provider
<Provider store={store} context={MyContext} />
// provide to all of your connected components
// two ways of doing this:
connect(mapState, mapDispatch, null, { context: MyContext })(MyComponent)
// or
const MyConnectedComponent = connect(mapState, mapDispatch)(MyComponent)
<MyConnectedComponent context={MyContext} /> |
Up through v5, We do need to document this, but this is intentional, and part of the reason for the major version bump. |
It should show a more descriptive error though @markerikson @wgao19 |
I‘ve had the same problem and added PR #1134 that helps if the context prop does not contain a valid react context (as in the codesandbox example given above) |
Do you want to request a feature or report a bug?
Bug/Unexpected behavior
What is the current behavior?
When passing
context
prop to connected component, it's replacing originalContext
andconnect()
returning anundefined
.Related code line:
react-redux/src/components/connectAdvanced.js
Line 216 in 94799ef
Example:
https://codesandbox.io/s/mm039l9q7x
What is the expected behavior?
Not use
context
prop or document this behavior.Which versions of React, ReactDOM/React Native, Redux, and React-Redux are you using? Which browser and OS are affected by this issue? Did this work in previous versions of React-Redux?
Latest
The text was updated successfully, but these errors were encountered: