Last active
June 21, 2022 05:20
-
-
Save scarabaeus/ec11b738a8e6e260337e1c022a5541b4 to your computer and use it in GitHub Desktop.
XState: Guarded Transitions from `done.invoke.<service>`
This file contains 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
... | |
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