[feature-request] Expose custom context to hooks
See original GitHub issueWhat is the current behavior?
The Provider
component allows consumers to pass a custom context
, but the current hooks API does not allow that custom context to be used.
What is the expected behavior?
I’d like to be able to access a custom context via React Redux hooks. I’d expect this would be implemented with a “hook factory” pattern for performance reasons, but that’s an implementation detail.
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?
This issue is unique to the v7-hooks
branch. I suppose you could say this has never worked in previous versions of React Redux, since hook support is new 🙂or, it might be argued that the HOC pattern was able to access alternate contexts, so hook support would be incomplete without it.
Note: I have a PR prepared; I didn’t read the contributing guidelines until after I’d written the code, which is why I’m doubling back and creating the discussion issue now.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:13 (12 by maintainers)
Top GitHub Comments
Good point! I was trying to avoid making assumptions about the consumer’s application, but ended up assuming all use cases would look like mine instead. 😅
I’ll put up a PR within the next few days using the
create*
API you’ve proposed.I’ve got a branch with the following as a proposal:
This is just one way we could expose it; my proposal branch is mostly clean code but there’s still room for improvement.
The key pieces are
Subscription
anduseSelectorWithStoreAndSubscription
(factored out fromuseSelector
), so even if the only outcome of this request were to expose those two as exports, it would still permit custom contexts.