Skip to content

@xstate/react@7.0.0-beta.0

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 05 Nov 20:27
· 2 commits to main since this release
4829a7b

Minor Changes

  • 81dd3dd: useActorRef, useActor and useMachine accept an already-created actor, such as one from restoreActor. The snapshot option is removed; restore the actor with restoreActor from xstate/persist and pass it to the hook. The hook starts the actor on mount and stops it on unmount, as it does for actors it creates. Create the actor once per component instance.

    import { useActor } from '@xstate/react';
    import { restoreActor } from 'xstate/persist';
    
    function App({ persisted }) {
      const [actor] = useState(() => restoreActor(machine, persisted));
      const [snapshot, send] = useActor(actor);
      // ...
    }

    createActorContext(...).Provider accepts the same actor through its actor prop:

    <SomeContext.Provider actor={actor}>{children}</SomeContext.Provider>

Patch Changes

  • 6cf6982: XState v6 enters beta. No further breaking changes are planned for APIs tagged @public; any that are needed will be called out with a migration path. APIs tagged @experimental may still change.