Create multiple Redux Stores

Aziz Khambati
Jul 22, 2017 · 2 min read

Update: This blog post was written on July 22, 2017 for react-redux v5.x. With v6 onwards the API has changed, you can check out the new API on the official documentation: Create Multiple Stores

The orignal post is follows:

Before you read this post, I highly recommend you read this:

Also check out the various links to the discussions provided below the answer. That should deter you from creating multiple redux stores.

The Provider

Along with exporting Provider, connect, react-redux also exports a createProvider function. This takes in an argument storeKey which defines on what key of the context it needs to set the store. By default it is "store", so you can set it to be "myComponentStore".

Connect

The fourth parameter to connect is options which can take a storeKey key which will define from which key of context it needs to read the store.

Words of advice

You were so preoccupied with whether or not you could, you didn’t stop to think if you should.

The answer is to use combineReducers

Like you decided on a storeKey on the context where the store should reside, you decide on a key where your component’s state should reside in the store’s state.

The reason why we wanted to create multiple redux stores was that we created a complicated component with many screens and layouts which was going to be used in multiple websites in the React ecosystem, some which have Redux, some which don’t. So to make it easier to just plug and play we have created multiple redux stores.

Aziz Khambati

Written by

Everything Javascript @ Anarock, ex Housing.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade