xstate-codegen
xstate-codegen copied to clipboard
Putting machine options in separate files?
I'd like to be able to define my machine options in separate files so I can swap out real/mock service implementations like the following:
interface HomePageProviderProps {
machineOptions: any; // <-- How do I type this?
children: React.ReactNode;
}
const HomePageProvider = ({ machineOptions, children }: HomePageProviderProps) => {
const [state, send] = useMachine(homePageMachine, machineOptions)
return <HomePageStateContext.Provider value={state}>
<HomePageDispatchContext.Provider value={{}}>
{children}
</HomePageDispatchContext.Provider>
</HomePageStateContext.Provider>
}
Is there an easy way to get the generated types for my machine options so I can replace this any?
Replacing any with HomePageMachineStateMachine<HomePageMachineContext, HomePageMachineEvent, "homePageMachine">["_options"] seems to do the job. I'm fine with this unless there is a more reader-friendly way of doing it which I'm overlooking.