State Management · Junior · Question 27 of 75

Why can you "mutate" state inside createSlice reducers?

added(state, action) {
  state.items.push(action.payload);
}

Explanation

state is an Immer draft: you write mutating code, and Immer produces a new object with structural sharing. Outside createSlice/createReducer mutations are still bugs.

Further reading

Problem with a question

State Management · Junior · question 27

Test yourself

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

Take this quiz