Typescript not work well in complex state machine with React #4323
Unanswered
yangLiu57670838
asked this question in
General
Replies: 1 comment 1 reply
-
i can see how this might sometimes be problematic but it would still be great if you could give some code samples demonstrating the problem. With that, I could try to offer some solutions. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I have used xstate in our production, once the state machine grows, i realise that typegen cant work with splitted guard, event actions invoked children machine.. etc..
so I switched to just define context and event types by myself without typegen,
something like this:
createMachine<StateMachineContext, StateMachineEvents>
schema: {
context: {} as StateMachineContext,
events: {} as StateMachineEvents,
},
the type errors gone, however, without typegen, the state.matches() func and send() func have no more typescript hint.. for complex state machine, its really hard, cause children of children of children's state match means a lot of input in state.matched()
also, for invoked children state machine to work in React components, i have to:
const stateMachineService = useInterpret(... );
const [state] = useActor(stateMachineRef?.stateMachineService);
const [childrenState] = useActor(state.children.appContentRenderMachine);
which lead childrenState.send() have no typescript hint at all no matter its with typegen or without..
anyway, could I ask am i doing it wrong, or v5 will improve the typescript, thanks
Beta Was this translation helpful? Give feedback.
All reactions