Skip to content

Conversation

davidkpiano
Copy link
Member

Add setup().createAction(…) helper for type-safe custom actions.
Allow wrapping built-ins with createAction (e.g. createAction(assign(...)) or createAction(raise(...))).

const machineSetup = setup({
  types: {} as {
    context: {
      count: number;
    };
    events: { type: 'inc'; value: number };
  }
});

const action = machineSetup.createAction(({ context, event }) => {
  console.log(context.count, event.value);
});

const incrementAction = machineSetup.createAction(
  assign({ count: ({ context }) => context.count + 1 })
);

const machine = machineSetup.createMachine({
  context: { count: 0 },
  entry: [action, incrementAction]
});

Copy link

changeset-bot bot commented Sep 3, 2025

🦋 Changeset detected

Latest commit: 23dda30

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

This PR includes changesets to release 5 packages
Name Type
xstate Minor
@xstate/react Major
@xstate/solid Major
@xstate/svelte Major
@xstate/vue Major

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

@davidkpiano davidkpiano requested a review from Andarist September 3, 2025 14:02
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.

1 participant