Created
January 17, 2023 17:36
-
-
Save chrisjbrown/c98db10102d89e458ebe382107722bb7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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