Why Provider component and context needed?
See original GitHub issueAs I understood from the source code of Provider
and connect
, Provider
acts as a dependency container that holds the store and makes it available for the connect
. My question is, why it should be a component and why it should use React’s context at all?
Wouldn’t it be possible to just define a module that holds the created store as a local variable in the module?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Context - React
Context is primarily used when some data needs to be accessible by many components at different nesting levels. Apply it sparingly because it...
Read more >Provider Pattern with React Context API - Flexiple
To solve this problem, we would need a global object to which components can have direct access in the react tree. React's context...
Read more >Why Is React Context.Provider Necessary (Or useful)?
The purpose for having a Context Provider wrap around children is to keep track of state and props, read on how ...
Read more >How to use React Context effectively - Kent C. Dodds
The Custom Provider Component. Ok, let's continue. For this context module to be useful at all we need to use the Provider and...
Read more >A Guide to React Context and useContext() Hook
2. When do you need context? ... The main idea of using the context is to allow your components to access some global...
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
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Singletons, especially stateful ones, are usually an antipattern. This especially would be bad for server-side.
Thanks for your answers.