Created
May 20, 2020 20:43
-
-
Save kyleshevlin/91ecb7b7e2509f3f43528ab9f4a7acde to your computer and use it in GitHub Desktop.
a state chart for a signup form
This file contains hidden or 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 submitEvent = { | |
SUBMIT: [ | |
{ | |
target: 'submitting', | |
cond: 'isValidData', | |
}, | |
{ target: 'error' }, | |
], | |
} | |
const signupMachine = Machine({ | |
id: 'signup', | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
...submitEvent, | |
}, | |
}, | |
submitting: { | |
invoke: { | |
id: 'submitData', | |
src: 'submitData', | |
onDone: 'success', | |
onError: 'failure', | |
}, | |
}, | |
error: { | |
on: { | |
...submitEvent, | |
}, | |
}, | |
success: {}, | |
failure: { | |
on: { | |
RETRY: 'submitting', | |
}, | |
}, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment