So, my idea is to enhance an already created store with my own store...
A pseudo code would be something like this:
const store = createStore(reducer);
const myStore = createStore(reducer);
enhanceStore(store, myStore);
The purpose of this is that I'm creating a library that uses redux under the hood, today I'm configuring my own library store... But I wan't to be able to check if the user is already using redux, in that case I want to merge my store with his.
It's not mandatory to merge 2 stores, perhaps I can enhance the already created store with a new reducer...
Thanks!
As with several other questions, it is possible to create multiple distinct Redux stores in a page, but the intended pattern is to have only a single store. Having a single store enables using the Redux DevTools, makes persisting and rehydrating data simpler, and simplifies the subscription logic.
Create a context for each store. You can also import ReactReduxContext from react-redux and use it for one of the stores, which you want to make default. Now wrap the root component of the react application with a provider for each store, passing the contexts as props.
If the whole application be well-managed, one store can be enough to manage the whole application status...
I hope you're looking for store.replaceReducer()
It is an advanced API. You might need this if your app implements code splitting, and you want to load some of the reducers dynamically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With