Modular and easy-to-grasp redux based state management, with least boilerplate
JavaScript HTML CSS
Switch branches/tags
Nothing to show
Latest commit 3213b9e Mar 10, 2018


Redux Box

Setting up and organizing a redux store in your react/react-native projects can be a tedious and daunting task. Redux-Box aims at abstracting away the complexity in using redux with redux-saga, while letting you manage application state in modular fashion, without losing the flexibility or without introducing new bizarre terms.


Illustration by Vikas

Table of contents:

What's it for:

  1. Clean, expressive and minimal reducers: If you prefer keeping your code expressive, you will feel right at home with redux-box. Have a look at a simple reducer written with and without redux-box:


If you are concerned about the state getting mutated directly in the snippet above, then you need not be. Because the state being passed to a mutation is NOT the actual state object of application, instead it's a Proxy of the state. Redux-box relies on wonderful immer library to achieve the expressiveness you see above.

  1. Organise your giant state into modules
  2. Setup redux+redux-saga for our react/react-native app in a trice
  3. Simplified Sagas
  4. Just import and use store: You wouldn't need to write a dedicated HOC to interact with your store. If you need to interact with a particular store-module, you can simply import it and use it. As simple as that! Redux box offers two ways of using a module in your component : using @connectStore decorator or using render props. (refer to the usage section for better reference)


Run this command in your terminal/cmd to install the package:

npm install --save redux-box


yarn add redux-box

NOTE: In case you receive error for es6 features make sure to install babel-polyfill as well:

npm install --save babel-polyfill

and then import the polyfill in your App.js

import polyfill from 'babel-polyfill'

The Basics

Redux box emphasizes on dividing the whole application into multiple modules. Each of these modules manages it's state seperately, with the help of 4 segments:

  1. state (It specifies the initial state of the module)

  2. mutations (It specifies the function to be run when a specific action is dispatched, it's same as reducer but clutter-free)

  3. actions (it contains the actionCreators for your store. Each method of this object must return an action object )

  4. sagas (this is where you write all your sagas / async operations)


step 1: create a module

Make sure you specify a unique name for each module ('user' in this example)

// store/user.js
import { createSagas, createContainer } from "redux-box";
import { call } from "redux-saga/effects";

const state = {
  name: "John",
  email: ""

const actions = {
  setName: name => ({ type: "SET_NAME", name }),
  setEmail: email => ({ type: "SET_EMAIL", email })

const mutations = {
  SET_NAME: (state, action) => ( =,
  SET_EMAIL: (state, action) => ( =

const sagas = createSagas({
  SET_EMAIL: function*(action) {
    const response = yield call(api.updateEmail,;

export const module = {
  name: "user",

//OPTIONAL: if you want to access this module using render props in your components:
export default createContainer(module);

NOTE: There also exists an optional shorthand to create actions rapidly, like so:

import {createActions, using} from 'redux-box'

const actions= createActions({
  setName: using('name'),
  setEmail: using('email')

The actionCreators generated by this code are same as the ones generated by the above code.

step 2 : register the module in redux store

import { createStore } from "redux-box";
import { module as userModule } from "./user";
import { module as postModule } from "./post";

export default createStore([userModule, postModule]);

OPTIONAL: if you need to create store with some reducers and middlewares, the signature of createStore method from redux-box goes like this:(if you have already included a module in modules array, you need NOT to register it's sagas or reducers manually by including in config object)

import { moduleToReducer } from "redux-box";

createStore((modules: Array), (config: Object));

//example config object
config = {
  middlewares: [],

  // sagas to be manually registered
  sagas: [userModule.sagas, testModule.sagas],

  // reducers to be manually registered
  reducers: {
    user: moduleToReducer(user)
  decorateReducer: reducer => {
    //do something
    return newReducer;

After this you would need to wrap your root component around the Provider tag like so :

import React from "react";
import { Provider } from "react-redux";
import store from "./store";
import RootComponent from "./components/RootComponent";

class App extends React.component {
  render() {
    return (
      <Provider store={store}>
        <RootComponent />

export default App;

step 3: Use the module in component

through decorator

import React, { Component } from "react";
import { module as userModule } from "store/user";
import { connectStore } from "redux-box";

  user: userModule //  AppComponent receives 'user' as a prop
export default class AppComponent extends Component {
  componentDidMount() {
                                    name : 'John',
                                    email : '',
                                    setName : fn(arg),
                                    setEmail : fn(arg)

  render() {
    const { user } = this.props;
    return (
	<button onClick={()=>{ 
	  user.setName('jane doe')
	}}> Change Name </button>

or through render props

import React, {Component} from 'react'
import UserModule from 'store/user'

export default class AppComponent extends Component{
      {(user)=> (
        <p> {} </p>
	<p> {} </p>

Live Examples

Here are some examples to let you play around with redux-box

  1. Basic example -
  2. Example showing redux-saga usage: -
  3. Example usage with redux-form:
  4. Example usage with redux-persist :

Upcoming Features

No pending feature requests

Suggest a new feature here


  1. Can I use all the features of redux-box, with createStore from redux instead?

Yes, you can! Here's the script showing how you can use createStore from redux, to setup your modules (with reducers, sagas and middlewares): (v1.3.9 onwards)

import { applyMiddleware, combineReducers, compose, createStore } from "redux";
import createSagaMiddleware from "redux-saga";
import { all } from "redux-saga/effects";
import { moduleToReducer } from "redux-box";
import { module as homeModule } from "./home";
import { module as userModule } from "./user";

//hook up your module reducers
const combinedReducer = combineReducers({
  home: moduleToReducer(homeModule),
  user: moduleToReducer(userModule)

// hook up your module sagas
const sagas = [...homeModule.sagas, ...userModule.sagas];

// hook up your middlewares here
const sagaMiddleware = createSagaMiddleware();
const middlewares = [sagaMiddleware];

//what follows below is the usual approach of setting up store
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
let enhancer = composeEnhancers(applyMiddleware(...middlewares));

function* rootSaga() {
  yield all(sagas);

const store = createStore(combinedReducer, enhancer);;
export default store;