I want to send an event to a different spawned state machine using its ID, which I have stored as a string in a variable within the context. This state machine is neither the parent nor child.
For example:
context.sendTo = 'B_id'
How can I use send()
with a parameter from the context?
Also, how do I include
send('MY_EVENT_NAME', {to: <something from context> })
in the actions
section of MachineOptions
?
// this does not work...
const myMachineOptions:Partial<MachineOptions<any,any>> =
{
actions:{
mySend: (context, event)=>send('MY_EVENT_NAME', {to: context.sendTo })
}
}
P.S.
This is similar to the question asked in Pass values when sending events from one machine to another in xState
However, what I need to be dynamic is not the message body but the to:
part