-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
-
-
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
Why Provider component and context needed? #719
Comments
Yes, it would be possible to explicitly import the store everywhere, but that makes testing and SSR much more difficult. See http://redux.js.org/docs/faq/StoreSetup.html#store-setup-multiple-stores . Since |
I think you misunderstood my question. I am asking why // provider.js (in react-redux package - Hypothetically)
let store;
const registerStore = (store) => store = store;
const getStore = () => store;
export { registerStore, getStore };
// connect.js (in react-redux package - Hypothetically)
import { getStore } from './provider';
// same connect code but just use getStore to access to the store.
// index.js
import { createStore } from 'redux';
import { registerStore } from 'react-redux';
const store = createStore(rootReduer, enhancer);
registerStore(store);
... |
Singletons, especially stateful ones, are usually an antipattern. This especially would be bad for server-side. |
Yep - the linked FAQ entry discusses this. |
Thanks for your answers. |
As I understood from the source code of
Provider
andconnect
,Provider
acts as a dependency container that holds the store and makes it available for theconnect
. 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?
The text was updated successfully, but these errors were encountered: