State Management
Immutability
Immutability means you never modify existing state. Each update produces a new state object.
Why it matters
- Reliable change detection via reference checks
- Predictable updates and debug traces
- Enables memoization and time-travel tooling
In Redux and RTK
- Reducers must return new objects
- RTK uses Immer to allow mutation-like syntax while keeping immutability
// correct
return { ...state, count: state.count + 1 }