The basic idea is that you will modify (a proxy of) the current state, and once that is completed, the copy will be finalized and form the next state.
As soon as a piece of the state is modified, it is copied. That is what one typically does by hand (in for example Redux reducers).
_This means that you can interact with your data by using mutations, will keeping all the benefits of immutable data_
_This means that you can interact with your data by using mutations, while keeping all the benefits of immutable data_
The immer package exposes a single function:
`immer(currentState, fn: (state) => void): nextState`
113 unmodified lines
Expand all
* Currently only supports plain objects and arrays. Non-plain data structures (like `Map`, `Set`) not (yet). (PR's welcome)
## Pitfalls:
* Make sure to modify the state you get passed in in the callback function, not the original base state that was passed as first argument to `immer`!
No newline at end of file
* Make sure to modify the state you get passed in in the callback function, not the original base state that was passed as first argument to `immer`!