Skip to content

Instantly share code, notes, and snippets.

@scarabaeus
Last active June 21, 2022 05:20
Show Gist options
  • Save scarabaeus/ec11b738a8e6e260337e1c022a5541b4 to your computer and use it in GitHub Desktop.
Save scarabaeus/ec11b738a8e6e260337e1c022a5541b4 to your computer and use it in GitHub Desktop.
XState: Guarded Transitions from `done.invoke.<service>`
...
validating: {
invoke: {
src: 'validateMobileNumber',
onDone: [
{
target: 'valid',
actions: assign({mobileNumberError: ''}),
cond: (_ctx, event) => {
const validationResponse = event.data;
if (validationResponse.result) {
return true;
} else {
return false;
}
}
},
// If the condition is false, validation failed, so go to invalid
{
target: 'invalid',
actions: assign((_ctx, event) => ({ mobileNumberError: event.data.validationMessage }))
}
],
onError: { ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment