Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Pass state input to timeout, onTimeout, after and event handlers#5597

Merged
davidkpiano merged 1 commit into
statelyai:nextfrom
asfktz:pass-state-input-to-handlers
Jul 6, 2026
Merged

Pass state input to timeout, onTimeout, after and event handlers#5597
davidkpiano merged 1 commit into
statelyai:nextfrom
asfktz:pass-state-input-to-handlers

Conversation

@asfktz

@asfktz asfktz commented Jul 6, 2026

Copy link
Copy Markdown

State input is already available in a state's entry and exit actions.
This PR makes it available in event handlers, after, timeout, and onTimeout as well.

const machine = setup({
  states: {
    active: {
      schemas: { input: z.object({ duration: z.number() }) }
    }
  }
}).createMachine({
  initial: 'idle',
  states: {
    idle: {
      on: {
        activate: ({ event }) => ({
          target: 'active',
          input: { duration: event.duration }
        })
      }
    },
    active: {
      timeout: ({ input }) => input.duration,
      onTimeout: ({ input }) => ({ target: 'idle' }),
      after: {
        1000: ({ input }) => ({ target: 'idle' })
      },
      on: {
        ping: ({ input }, enq) => {}
      }
    }
  }
});

@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 754b686

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
xstate Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@asfktz asfktz changed the base branch from main to next July 6, 2026 04:08
@asfktz asfktz force-pushed the pass-state-input-to-handlers branch from 6043f37 to 754b686 Compare July 6, 2026 04:12
@davidkpiano davidkpiano merged commit 5649f6f into statelyai:next Jul 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants