github statelyai/xstate @xstate/react@1.1.0

3 years ago

Minor Changes

  • 89f9c27c #1622 Thanks @davidkpiano! - Spawned/invoked actors and interpreters are now typed as extending ActorRef rather than Actor or Interpreter. This unification of types should make it more straightforward to provide actor types in React:

    import { ActorRef } from 'xstate';
    import { useActor } from '@xstate/react';
    
    const Child: React.FC<{ actorRef: ActorRef<SomeEvent, SomeEmitted> }> = ({
      actorRef
    }) => {
      // `state` is typed as `SomeEmitted`
      // `send` can be called with `SomeEvent` values
      const [state, send] = useActor(actorRef);
    
      // . ..
    };

    It's also easier to specify the type of a spawned/invoked machine with ActorRefFrom:

    import { createMachine, ActorRefFrom } from 'xstate';
    import { useActor } from '@xstate/react';
    
    const someMachine = createMachine<SomeContext, SomeEvent>({
      // ...
    });
    
    const Child: React.FC<{ someRef: ActorRefFrom<typeof someMachine> }> = ({
      someRef
    }) => {
      // `state` is typed as `State<SomeContext, SomeEvent>`
      // `send` can be called with `SomeEvent` values
      const [state, send] = useActor(someRef);
    
      // . ..
    };

Don't miss a new xstate release

NewReleases is sending notifications on new releases.