Skip to content

Instantly share code, notes, and snippets.

@davidkpiano
Last active November 1, 2020 21:16
Show Gist options
  • Save davidkpiano/bbcb4379b36edea0458f597e5eec2f91 to your computer and use it in GitHub Desktop.
Save davidkpiano/bbcb4379b36edea0458f597e5eec2f91 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
Machine({
id: 'Dog API',
initial: 'idle',
context: {
dog: null
},
states: {
idle: {
on: {
FETCH: 'loading'
}
},
loading: {
invoke: {
id: 'fetchDog',
src: (context, event) => fetch('https://dog.ceo/api/breeds/image/random')
.then(data => data.json()),
onDone: {
target: 'resolved',
actions: assign({
dog: (_, event) => event.data
})
},
onError: 'rejected'
},
on: {
CANCEL: 'idle'
}
},
resolved: {
type: 'final'
},
rejected: {
on: {
FETCH: 'loading'
}
}
}
})
@NicholasBoll
Copy link

On line 16, is the site .co or .dev? The docs say .dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment