I have an xstate state machine with 3 states. When data is fetched and final state isreached, the state machine is 'Done'. I would like to go back to initial state of idle after 'finally completing the task'. How do I accomplish that? For example,
states: {
idle: {
id: 'initialState'
},
waitingForA: {
invoke: { /*Promise*/ },
onDone: { target: 'wiatingForB' },
onError: { alert(); }
},
waitingForB: {
invoke: { /*Promise*/ },
onDone: {
target: 'waitingForC',
actions: assign({ bReturnCode: (context, event) => event.data, })
}
},
waitingForC: {
invoke: { /*Promise*/ },
onDone: {
target: 'success',
actions: assign({ cReturnCode: (context, event) => event.data, })
},
onError{
target: 'showAlert'
}
},
success: {
type: 'final' //here, I would like ot go back to idle state;
},
final: {target: 'idle'}
}
}