Multiple stores

Handling multiple stores in a React-Redux application

In a react-redux application, it is a good practice to have only one redux store. But if for some weird/“special” reason if you have to have more than one store, you will face some problems. The most common problem is that if we wrap a component with a provider and then wrap a child component with another provider, it’s not easy to subscribe to the store of top-level provider. const Component1 = () => { return ( <Provider store={store1}> <Provider store={store2}> <Component2 /> </Provider> </Provider> ); }; It’s so confusing that within a few iterations of development, you’ll find yourself using providers on each component, and not being able to read values from both the stores in a single component will frustrate you....

October 12, 2021 · 2 min · Vikas Kumar