A function passed to edit. The editor is called back with a
draft - a mutable proxy of the Store's current RootState.
You can make changes to the mutable draft proxy within your editor callback
using any javascript syntax. When it returns,
Immer efficiently composes a new
state to reflect your drafted changes, leaving the old state
intact. The new state is passed to @watchable/store!Store#write.
The editor is equivalent to Immer's producer except returning a value doesn't
replace the @watchable/store!RootState. To replace the state call @watchable/store!Store#write instead
of using an editor. This eliminates Immer's runtime errors when you draft
changes as well as returning a value, (easily done by accident in simple
arrow functions).
See Immer docs for more detail on
the conventions for Immer producers.
A function passed to edit. The editor is called back with a
draft
- a mutable proxy of the Store's currentRootState
.You can make changes to the mutable
draft
proxy within your editor callback using any javascript syntax. When it returns, Immer efficiently composes a new state to reflect your drafted changes, leaving the old state intact. The new state is passed to @watchable/store!Store#write.The editor is equivalent to Immer's producer except returning a value doesn't replace the @watchable/store!RootState. To replace the state call @watchable/store!Store#write instead of using an editor. This eliminates Immer's runtime errors when you draft changes as well as returning a value, (easily done by accident in simple arrow functions).
See Immer docs for more detail on the conventions for Immer
producers
.