Skip to content

Instantly share code, notes, and snippets.

@condratf
condratf / combineUseReducers.js
Created May 28, 2020 17:36 — forked from thchia/combineUseReducers.js
Combining the useReducers Hook
// Main
function combineReducers(reducerDict) {
const _initialState = getInitialState(reducerDict);
return function(state = _initialState, action) {
return Object.keys(reducerDict).reduce((acc, curr) => {
let slice = reducerDict[curr](state[curr], action);
return { ...acc, [curr]: slice };
}, state);
};
}