createSliceintermediatereducers: {
setTheme: (state, action) => {
state.user.preferences.theme = action.payload
},
}Immer lets you write deeply nested mutations naturally β no need to spread every level of the state tree.
Immer handles deeply nested state mutations transparently. You can assign to nested properties just like plain JavaScript.
Challenge: Create a profile slice with nested user.preferences.theme and write reducers to update the name and theme.
profileSlice.reducer(undefined, setTheme('dark'))
// β { user: { name: '', preferences: { theme: 'dark' } } }