Why does my Redux reducer think my state is undefined?

前端 未结 1 1825
迷失自我
迷失自我 2021-01-17 20:22

I believe I\'m copying the Todo tutorial pretty much line for line, I am getting this error:

Error: Reducer \"addReport\" returned undefined during in

相关标签:
1条回答
  • 2021-01-17 20:59

    You are missing the default of the switch case.

    default: {
      return {
        ...state
      }
    }
    

    Redux won't play along like a nice kid if you forget to do it!

    Or alternatively, you can explicitly return at the end the initial state: If the state passed to the reducer is undefined, you must explicitly return the initial state.

    0 讨论(0)
提交回复
热议问题