Access store from context?
See original GitHub issueHi, I just updated to 6.0.0 and have a question. I can’t really figure out from the docs how to access the store from context anymore.
My app is wrapped with
<Provider store={store}>
Then in any component I could access it with
MyComponent.contextTypes = {
store: PropTypes.object.isRequired
};
->
this.context.store
How do i achieve the same thing with 6.0.0?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Accessing the Store | React Redux
Internally, React Redux uses React's "context" feature to make the Redux store accessible to deeply nested connected components.
Read more >Accessing the Store with React-Redux - Medium
Provider to put the Redux Store and the current state into context and connect uses ReactReduxContext.Consumer to read values and handle updates ...
Read more >Redux: Passing the Store Down Implicitly via Context
Learn how to make the store object available to all components by using the advanced React feature called “context”.
Read more >React: Accessing context from within a Redux store
I need to use values on the SocketProvider context in my store What does that mean? You want to use it in reducers,...
Read more >How to Work with the React Context API - Toptal
Let's refactor the app and demonstrate what it can do. In a few words, the Context API allows you to have a central...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
Note that
contextTypes
andcontextType
are not the same thing.React defines legacy context using syntax like:
When the new context API was released, it originally could only be used via a render-props API:
To help with the migration from old context to new context, the React team added a new way to access new context in 16.6 called
contextType
:So, you should be able to do:
If you want that, you can just make your own context:
The new API is really simple 👍