Persisting state in DB #3962
-
Hello everyone, Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
At minimum, you only need to store the Then, you can recreate the state (XState v4 code): import { State } from 'xstate';
const someMachine = createMachine({...});
// ... get value and context from DB
const restoredState = State.from(value, context);
// Resolves the state so that it is compatible with someMachine
const resolvedState = someMachine.resolveState(restoredState);
interpret(someMachine).start(resolvedState); |
Beta Was this translation helpful? Give feedback.
At minimum, you only need to store the
state.value
andstate.context
if applicable.Then, you can recreate the state (XState v4 code):