patchoperator will become your best friend in case of choosing state operators as your immutability helpers. Let's see how we could re-write the above code with the help of the
immeris a very popular library that allows you to make changes to immutable objects as if they were mutable. The below code shows how to write the same code with the help of Immer:
producefunction can be also used as a state operator:
Using Immer is like having a personal assistant; he takes a letter (the current state) and gives you a copy (draft) to jot changes onto. Once you are done, the assistant will take your draft and produce the real immutable, final letter for you (the next state).
immutability-helperis a small package that lets you mutate a copy of data without changing the original source:
object-path-immutableis a small library that allows you to modify deep object properties without modifying the original object. Let's look at how we could write the same code using this library:
immutable-assignis a lightweight library that pursues the same goal. Its syntax is similar to
icepickis a zero-dependency library for working with immutable collections. Given the following re-written code: