Using Immer for Temporary Mutations
Explore how to use Immer to write Redux reducers that allow temporary mutations while maintaining immutability. Learn to simplify state updates, reduce boilerplate, and avoid accidental state changes after reducer execution.
We'll cover the following...
A word from our friend Michel Weststrate, creator of MobX and Immer:
When writing reducers, it can sometimes be beneficial to use mutable objects temporarily. This is fine as long as you only mutate new objects (and not an existing state) and as long as you don’t try to mutate the objects after they have left the reducer.
Immer is a tiny library that expands this idea and makes it easier to write reducers. It is comparable in functionality to the withMutations() method in Immutable.js, but applied to regular JavaScript structures. With this approach, ...