Reduce multiple reducers into a single reducer from left to right
npm install reduce-reducers
import reduceReducers from 'reduce-reducers';
const initialState = { A: 0, B: 0 };
const addReducer = (state, payload) => ({ ...state, A: state.A + payload });
const multReducer = (state, payload) => ({ ...state, B: state.B * payload });
const reducer = reduceReducers(addReducer, multReducer, initialState);
const state = { A: 1, B: 2 };
const payload = 3;
reducer(state, payload); // { A: 4, B: 6 }
Originally created to combine multiple Redux reducers that correspond to different actions (e.g. like this). Technically works with any reducer, not just with Redux, though I don't know of any other use cases.
This StackOverflow post explains it very well: https://stackoverflow.com/a/44371190/5741172