Skip to content

Persisting state in DB #3962

Answered by davidkpiano
arbhuiyan asked this question in Q&A
Discussion options

You must be logged in to vote

At minimum, you only need to store the state.value and state.context if applicable.

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);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by arbhuiyan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants