multiple reducers in context api

Solutions on MaxInterview for multiple reducers in context api by the best coders in the world

showing results for - "multiple reducers in context api"
Maxime
01 May 2019
1const initialState = {
2  random: { value: 0 },
3  counter: 0,
4}
5
6const combineReducers = reducers => {
7  return (state, action) => {
8    return Object.keys(reducers).reduce(
9      (acc, prop) => {
10        return ({
11          ...acc,
12          ...reducers[prop]({ [prop]: acc[prop] }, action),
13        })
14      },
15      state
16    )
17  }
18}
19
20export { initialState, combineReducers }