Skip to content

Instantly share code, notes, and snippets.

@LevelbossMike
Created March 25, 2020 17:04
Show Gist options
  • Select an option

  • Save LevelbossMike/75fa670f88452661b0cb1182c2391d9e to your computer and use it in GitHub Desktop.

Select an option

Save LevelbossMike/75fa670f88452661b0cb1182c2391d9e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
function notifyActionName(context, event) {
window.alert(`Triggered action \`${event.type}\``)
}
const fetchMachine = Machine( {
id: 'quickstart-button-step-6',
initial: 'idle',
states: {
idle: {
on: {
SUBMIT: 'busy',
},
},
busy: {
onEntry: ['handleSubmit'],
on: {
SUCCESS: 'success',
ERROR: 'error',
},
},
success: {
onEntry: ['handleSuccess'],
},
error: {
onEntry: ['handleError'],
},
},
},
{
actions: {
handleSubmit: notifyActionName,
handleSuccess: notifyActionName,
handleError: notifyActionName,
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment