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
reducers/testRedducer.js
// 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
}
}