Update patterns
Working with immutable data, before Immer, used to mean learning all the immutable update patterns.
To help 'unlearning' those patterns here is an overview how you can leverage the built-in JavaScript APIs to update objects and collections:
#
Object mutations#
Array mutations#
Nested data structuresNote that many array operations can be used to insert multiple items at once by passing multiple arguments or using the spread operation: todos.unshift(...items)
.
Note that when working with arrays that contain objects that are typically identified by some id, we recommend to use Map
or index based objects (as shown above) instead of performing frequent find operations, lookup tables perform much better in general.