XState v6 alpha
Persist and restore actors
Save an actor snapshot and restore it later.
XState v6 is in alpha
APIs and behavior may change before the stable release.
Use getPersistedSnapshot() to get serializable actor state.
const actor = createActor(machine).start();
actor.send({ type: 'next' });
const stored = JSON.stringify(actor.getPersistedSnapshot());
actor.stop();Pass the parsed snapshot to createActor(...) when restoring the actor.
const restored = createActor(machine, {
snapshot: JSON.parse(stored)
}).start();Persisted snapshots include persisted child actors. Store the machine version with each snapshot and keep external resources out of context.
Restore a checkout after a refresh or resume an order when the next webhook arrives. Do not restore an old snapshot with incompatible actor logic.