modifyMutable
Edit this pagemodifyMutable
streamlines the process of making multiple changes to a mutable Store, as obtained through the use of [createMutable]/reference/store-utilities/create-mutable).
It operates within a single batch
, ensuring that dependent computations are updated just once, rather than triggering updates for each individual change.
The function takes two arguments:
- The first argument is the mutable Store that needs modification.
- The second argument is a Store modifier, which could be one of those returned by
reconcile
.
When passing in your own modifier function, it's important to be aware that its argument is an unwrapped version of the store.
For example, if the UI depends on multiple fields of a mutable:
Modifying n fields in sequence will cause the UI to update n times:
To trigger just a single update, the fields can be modified using a batch
:
modifyMutable
combined with reconcile
or produce
provides two alternate ways to do similar things: