Skip to content

Instantly share code, notes, and snippets.

@chrisjbrown
Created January 17, 2023 17:36
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 chrisjbrown/c98db10102d89e458ebe382107722bb7 to your computer and use it in GitHub Desktop.
Save chrisjbrown/c98db10102d89e458ebe382107722bb7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const searchMachine = Machine({
id: 'search',
initial: 'idle',
context: {
results: [],
errorMessage: null,
},
states: {
idle: {
on: { FETCH: 'loading' },
},
loading: {
invoke: {
src: () => ({}),
onDone: {
target: 'success',
actions: assign({
results: (_, event) => event.data,
}),
},
onError: {
target: 'error',
actions: assign({
errorMessage: (_, event) => event.data,
}),
},
},
},
success: {
on: { FETCH: 'loading' },
},
error: {
on: { FETCH: 'loading' },
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment