The Rematch Immer plugin
As you'll remember from when we spoke about immutability and how Redux and Rematch handle changes of state, Redux forced us to create a new copy of the state on every reducer; we couldn't just mutate the current state and return it because it caused incorrect renders and it's not the correct way of doing things.
Immer.js is a tiny package that allows us to work with immutable state in a more comfortable way because it's based on the copy-on-write mechanism.
The idea is that you will apply your changes to a temporary draft state that is a proxy of the current state. Once all our mutations are done, Immer will produce the next state based on the mutations to the draft state.
To be clearer, instead of spreading and cloning our state all the time, we can just make safe mutations to our state, resulting in an immutable state.
Installation and configuration
To install @rematch/immer
, you can use yarn
and install it as follows: