Skip to content

Instantly share code, notes, and snippets.

@renerbaffa
Created April 7, 2020 18:31
Show Gist options
  • Save renerbaffa/458037c3dd3e959d6bd205ddd2e9f312 to your computer and use it in GitHub Desktop.
Save renerbaffa/458037c3dd3e959d6bd205ddd2e9f312 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
function fetchData() {
return new Promise((resolve, reject) => {
setTimeout(() => {
reject();
}, 1000);
});
}
const goatMachine = Machine({
initial: "idle",
states: {
idle: {
on: {
CLICK: "loading"
}
},
loading: {
invoke: {
src: () => fetchData(),
onError: "error",
onDone: "idle"
}
},
error: {
on: {
CLICK: "loading"
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment