Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to merge created stores in redux?

Tags:

reactjs

redux

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!

like image 790
Mauricio Soares Avatar asked Jul 07 '16 01:07

Mauricio Soares


People also ask

Is it possible to have multiple stores in Redux?

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.

How do I use multiple stores in react Redux?

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.

How many stores can we have in Redux?

If the whole application be well-managed, one store can be enough to manage the whole application status...


1 Answers

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.

like image 92
code-jaff Avatar answered Sep 24 '22 23:09

code-jaff