Creating state machines with shared context across instances #39
-
Here my test machine. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think what you want to achieve can be done with sharing the same context between state machines. However that would require some modifications: interface TestContext {
state: ExState;
}
export const sharedContext: TestContext = {
state: ExState.initial,
}; And in your component: const machine1 = useMachine(testMachine, { context: sharedContext });
// These instances should share same state
const machine2 = useMachine(testMachine, { context: sharedContext }); Of course this in itself won't work, since you would have to update state machine to use |
Beta Was this translation helpful? Give feedback.
I think what you want to achieve can be done with sharing the same context between state machines. However that would require some modifications:
And in your component:
Of course this in itself won't work, since you would have to update state machine to use
assign()
to update the context, and for that I recommend you check documentation reference