Redux reducers initializing same state key

前端 未结 2 1392
[愿得一人]
[愿得一人] 2021-02-07 07:23

I\'m messing around with the \'simplest-redux-example\' on github and I\'ve added a second reducer that decrements state.count. If I have the increment and decrement reducers i

2条回答
  •  爱一瞬间的悲伤
    2021-02-07 07:58

    You're so close! The catch is that when you use combineReducers it actually splits the "state" such that the states of the reducers you feed in are properties on the "state" object.

    As such, in order to feed them default parameters as follows: let store = createStore(rootReducer, {counter: {count: 0}, decrementer: {count:0}});

提交回复
热议问题