Creating state machines with shared context across instances #39
|
Here my test machine. |
Answered by
Lexpeartha
May 13, 2023
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 |
2 replies
Answer selected by
Lexpeartha
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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