Skip to content

Instantly share code, notes, and snippets.

@AlexFrazer
Created May 11, 2021 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexFrazer/76b3db4f3ac14acf8f228c72457c5e41 to your computer and use it in GitHub Desktop.
Save AlexFrazer/76b3db4f3ac14acf8f228c72457c5e41 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'Form Wizard',
initial: 'pending',
context: {
retries: 0
},
states: {
pending: {
initial: 'email',
states: {
email: {
on: {
NEXT: {
target: 'name',
cond: 'isEmailValid'
}
}
},
name: {
on: {
PREVIOUS: 'email',
NEXT: {
target: 'age',
cond: 'isNameValid',
}
}
},
age: {
on: {
PREVIOUS: 'name',
}
},
},
on: {
SUBMIT: {
target: 'submitting',
cond: 'isValid',
},
}
},
submitting: {
invoke: {
src: 'submit',
onDone: 'confirmed',
onError: {
target: 'error',
actions: assign({
error: (_ctx, action) => action.error,
})
}
}
},
confirmed: {
type: 'final',
},
error: {
on: {
RETRY: 'pending',
}
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment