Immer exposes a named export
current that creates a copy of the current state of the draft. This can be very useful for debugging purposes (as those objects won't be Proxy objects and not be logged as such). Also, references to
current can be safely leaked from a produce function. Put differently,
current provides a snapshot of the current state of a draft.
Objects generated by
current work similar to the objects created by produce itself.
- Unmodified objects will be structurally shared with the original objects.
- If no changes are made to a draft, generally it holds that
original(draft) === current(draft), but this is not guaranteed.
- Future changes to the draft won't be reflected in the object produced by
current(except for references to undraftable objects)
produceobjects created by
currentwill not be frozen.
current sparingly, it can be a potentially expensive operation, especially when using ES5.
current cannot be invoked on objects that aren't drafts.
The following example shows the effect of