useMachine.d.ts 1.5 KB

12345678910111213141516171819202122
  1. import { AnyStateMachine, AreAllImplementationsAssumedToBeProvided, EventObject, InternalMachineOptions, InterpreterFrom, InterpreterOptions, StateConfig, StateFrom } from 'xstate';
  2. import { MaybeLazy, Prop } from './types';
  3. export interface UseMachineOptions<TContext, TEvent extends EventObject> {
  4. /**
  5. * If provided, will be merged with machine's `context`.
  6. */
  7. context?: Partial<TContext>;
  8. /**
  9. * The state to rehydrate the machine to. The machine will
  10. * start at this state instead of its `initialState`.
  11. */
  12. state?: StateConfig<TContext, TEvent>;
  13. }
  14. declare type RestParams<TMachine extends AnyStateMachine> = AreAllImplementationsAssumedToBeProvided<TMachine['__TResolvedTypesMeta']> extends false ? [
  15. options: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta'], true>
  16. ] : [
  17. options?: InterpreterOptions & UseMachineOptions<TMachine['__TContext'], TMachine['__TEvent']> & InternalMachineOptions<TMachine['__TContext'], TMachine['__TEvent'], TMachine['__TResolvedTypesMeta']>
  18. ];
  19. declare type UseMachineReturn<TMachine extends AnyStateMachine, TInterpreter = InterpreterFrom<TMachine>> = [StateFrom<TMachine>, Prop<TInterpreter, 'send'>, TInterpreter];
  20. export declare function useMachine<TMachine extends AnyStateMachine>(getMachine: MaybeLazy<TMachine>, ...[options]: RestParams<TMachine>): UseMachineReturn<TMachine>;
  21. export {};
  22. //# sourceMappingURL=useMachine.d.ts.map