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 };
}

Explanation

Either mutate the draft (state.items.push(...); state.count += 1) or return a completely new state - Immer throws if you do both.

Further reading

Problem with a question

State Management · Middle · question 12

Test yourself

Take the State Management · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz