0.0.6 • Published 3 years ago

redux-root-reducer v0.0.6

Weekly downloads
8
License
ISC
Repository
github
Last release
3 years ago

Redux root-reducer

Allows you to combine multiple reducers into one for state management. Divide your reducer into smaller ones for easier code maintenance.

Installation

npm install redux-root-reducer
#or
yarn add redux-root-reducer

Example

folder structure

  reducers/
    testReducer.js
    testReducer2.js
  store.js
  rootReducer.js

rootReducer.js

import createRootReducer from 'redux-root-reducer';
import reducer from './reducers/testReducer.js';
import reducer2 from './reducers/testReducer.js';

const rootReducer = createRootReducer( reducer, reducer2 ); export default rootReducer

<br/>

>reducers/testRedducer.js
```javascript
// you can get and modify redux-state from within this function
export default function testReducer(state, action){ 
  switch (action.type){

    case 'ACTION_TYPE' : {
      // your code
      return {
        // return your new state
      }
    };
    case 'ACTION_TYPE2' : {
      // your code
    }

    // make sure to add a default section which return false
    default : return false
  }
}