State Management · Junior · Question 27 of 75
Why can you "mutate" state inside createSlice reducers?
added(state, action) {
state.items.push(action.payload);
}- ✓Correct answer: Immer turns these changes into an immutable update under the hood
- 2Redux Toolkit dropped the immutability requirement
- 3
pushis special-cased by RTK and other mutations are forbidden
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.