State Management · Middle · Question 12 of 75
What's wrong with this case reducer?
todoAdded(state, action) {
state.items.push(action.payload);
return { ...state, count: state.count + 1 };
}- ✓Correct answer: You can't both mutate the Immer draft and return a new value
- 2
pushis forbidden insidecreateSlicereducers - 3Case reducers must be async functions
Explanation
Either mutate the draft (state.items.push(...); state.count += 1) or return a completely new state - Immer throws if you do both.