Skip to content

xstate@6.0.0-alpha.16

Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 02 Jul 00:16
91d5bed

Minor Changes

  • e410f24: Add state-level onError transitions for handling xstate.error.* events.

    State onError catches actor, execution, and communication errors while the state is active. The caught error is available on event.error.

    const machine = createMachine({
      initial: 'active',
      states: {
        active: {
          onError: ({ event }) => ({
            target: 'failed',
            context: {
              message:
                event.error instanceof Error
                  ? event.error.message
                  : String(event.error)
            }
          })
        },
        failed: {}
      }
    });

Patch Changes

  • f6edec7: Allow machines with no external events to be used anywhere AnyActorLogic or AnyStateMachine is expected.

    const machine = setup({
      schemas: {
        events: {}
      }
    }).createMachine({});
    
    const logic: AnyActorLogic = machine;
    const anyMachine: AnyStateMachine = machine;

    Machines with empty event schemas still reject external events sent to their actors.