-
-
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
Pass through props.context to connected component #1278
Conversation
Deploy preview for react-redux-docs ready! Built with commit 70e0b08 |
Hmm. If we really were passing through |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any harm in make them available props. Since you can't do this.context
anymore, this serves as a replacement.
Without any major objections, I'm going to merge this in. If Mark feels strongly about it, we can certainly revert. |
I don't feel too strongly about it, but it does sorta feel like an implementation detail leaking into the wrapped component. The better question is, why do you feel a need to access the React-Redux context instance, in the wrapped component, as a prop? |
Here's the relevant code from connected-react-router: I don't know why its implemented like that right now – but it would probably be possible to implement it differently. |
I'm a little concerned about this change, we're unable to upgrade to react-redux@7 due to the context prop being forced into components now. The problem is, that we used My concern is not based on our blocking issue, because admittedly The link that @cmfcmf posted shows
|
The more I think about this, the less I like it. @timdorr , I think we ought to revert this change. That said, @jeffberry , I don't think this actually made it out into a release. |
@jeffberry This doesn't change anything on the incoming props side of thing. It only changes the outgoing props to the wrapped component, which will now include the // 7.0.0
<ConnectedThing context={context} {...otherProps} /> => <Thing {...otherProps} />
// This PR:
<ConnectedThing context={context} {...otherProps} /> => <Thing context={context} {...otherProps} /> So, even though it still needs to be a React Context, it's no longer hidden from the wrapped component. |
So there's two different issues here:
|
@timdorr: @markerikson has explained the issue we are facing perfectly; we can no longer have a prop named "context". We probably could've picked a more specific name on our part to begin with, but nonetheless, this is a breaking change for us. Let me know if there is anything I can provide to help drive a conclusion. EDIT: I should add that we are trying to upgrade from |
That one is unfortunately not going to change. We probably should have picked a different name for the "supply your own custom React context instance" prop, but it's too late now - that would require a breaking change on our part. I will admit that I don't think very many people are using that syntax, but semver-wise we'd have to bump a major again. (Note, however, that that existed as of v6, and has nothing to do with this PR.) |
To clarify, "up until now" means
That's good to know. If you were to update to v6, you would face the same issues with the context prop. The React Redux documentation has a section about using the context inside wrapped components to access the store: https://react-redux.js.org/using-react-redux/accessing-store#using-reactreduxcontext-directly const ConnectedRouterWithContext = props => {
const Context = props.context || ReactReduxContext
// ...
return (
<Context.Consumer>
{({ store }) => <ConnectedRouter store={store} {...props} />}
</Context.Consumer>
)
} |
@cmfcmf : and tbh, I view the fact that |
If the name of the react-redux/src/components/connectAdvanced.js Lines 174 to 176 in 8a1bb58
|
This issue came up when I tried to update connected-react-router to work with react-redux@7 (see supasate/connected-react-router#303).
In react-redux@6, you were able to do the following:
With react-redux@7, the context prop is no longer passed through to MyComponent. This PR "fixes" that. However, I'm really not an expert when it comes to React's context API and its usage in react-redux and connected-react-router. Let me know if this fix makes sense :)