The produce function takes a value and a "recipe function" (whose
return value often depends on the base state). The recipe function is
free to mutate its first argument however it wants. All mutations are
only ever applied to a copy of the base state.
Pass only a function to create a "curried producer" which relieves you
from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are
considered uncopyable.
Note: This function is bound to its Immer instance.
Param: base
the initial state
Param: producer
function that receives a proxy of the base state as first argument and which can be freely modified
Param: patchListener
optional function that will be called with all the patches produced here
Returns
a new state, or the initial state if nothing was modified
The
produce
function takes a value and a "recipe function" (whose return value often depends on the base state). The recipe function is free to mutate its first argument however it wants. All mutations are only ever applied to a copy of the base state.Pass only a function to create a "curried producer" which relieves you from passing the recipe function every time.
Only plain objects and arrays are made mutable. All other objects are considered uncopyable.
Note: This function is bound to its
Immer
instance.