Skip to content

Instantly share code, notes, and snippets.

@fauxparse
Last active January 17, 2023 20:36
Show Gist options
  • Save fauxparse/b42dd4d0903984fe9845c1206265ef48 to your computer and use it in GitHub Desktop.
Save fauxparse/b42dd4d0903984fe9845c1206265ef48 to your computer and use it in GitHub Desktop.
XState child state context
const Machine = createMachine({
context: {
name: '',
},
schema: {
context: {} as { name: string },
},
states: {
A: {
on: {
NEXT: 'B',
},
},
B: {
context: {
count: 0,
},
schema: {
context: {} as { count: number },
},
},
},
initial: 'A',
});
// ...
const service = interpret(Machine);
service.state.context // { name: '' }
service.send('NEXT')
service.state.context // { name: '', count: 0 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment