Why do I get “Reducer […] returned undefined during initialization” despite providing initialState to createStore()?

后端 未结 7 2260
死守一世寂寞
死守一世寂寞 2020-12-13 08:27

I had set InitialState in my redux createStore method ,and I corresponding InitialState as second arguments

I got a error in browser:

Un         


        
7条回答
  •  执笔经年
    2020-12-13 08:51

    I had the same error but I didn't include a default case

    function generate(state={} ,action) {
      switch (action.type) {
        case randomNumber:
          return {
            ...state,
            random: action.payload
          }   
        default: // need this for default case
          return state 
       }
    }
    

提交回复
热议问题