Answers for "multiple reducers in context api"

0

multiple reducers in context api

const initialState = {
  random: { value: 0 },
  counter: 0,
}

const combineReducers = reducers => {
  return (state, action) => {
    return Object.keys(reducers).reduce(
      (acc, prop) => {
        return ({
          ...acc,
          ...reducers[prop]({ [prop]: acc[prop] }, action),
        })
      },
      state
    )
  }
}

export { initialState, combineReducers }
Posted by: Guest on September-16-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language