erikras / multireducer

A utility to wrap many copies of a single Redux reducer into a single key-based reducer.
MIT License
422 stars 23 forks source link

state is undefined #105

Closed LopatkinEvgeniy closed 8 years ago

LopatkinEvgeniy commented 8 years ago

I have some reducer:

export default function someReducer (state = initState, action) {
  switch (action.type) {
    ....
  }
}

When i use it with multireducer there is error because action is undefined when multireducer initialize; To fix it i write that:

export default function someReducer (state = initState, action) {
if (!action) return state;

....
}

or that:

export default function someReducer (state = initState, action = {}) {
  ...
}
jsdmc commented 8 years ago

@LopatkinEvgeniy I prefer to set default action like in your example above. Redux dispatches INIT action when app starts. Since we don't rely on that action and call reducer manually to calculate initial state for multireducer - here your bug comes in. Will fix that.