question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why Provider component and context needed?

See original GitHub issue

As 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:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jimbollacommented, Jun 12, 2017

Singletons, especially stateful ones, are usually an antipattern. This especially would be bad for server-side.

0reactions
alisabzevaricommented, Jun 12, 2017

Thanks for your answers.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found