Redux & Redux Toolkit
/Beginner
Mutable Syntax with Immer
Definition
The specific JavaScript methods (like `push`, `pop`, `splice`, or direct reassignment) that were historically banned in Redux, but are now safely allowed inside RTK thanks to Immer.
Explain Like I'm New
For years, Redux developers were terrified of using `.push()`. With RTK, `.push()` is your best friend. Immer intercepts these 'dangerous' methods and makes them safe.
Real World Example
Deleting an item from an array. In legacy Redux, you had to use `.filter()`. In RTK, you can just use `.splice()`, which is much easier to read.
Common Use Cases
- •Writing cleaner, faster reducers
Interactive Example
Loading...
Console output will appear here...
Interview Questions
basic
- Is it safe to use `state.array.push()` inside a `createSlice` reducer?
intermediate
- If you mutate the state in RTK, should you ALSO `return` the state?