Last active
January 17, 2023 20:36
-
-
Save fauxparse/b42dd4d0903984fe9845c1206265ef48 to your computer and use it in GitHub Desktop.
XState child state context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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