Productivity

xstate

seed-hypermedia/seed · updated Apr 8, 2026

$npx skills add https://github.com/seed-hypermedia/seed --skill xstate
summary

CRITICAL: This skill covers XState v5 ONLY. Do not use v4 patterns, APIs, or documentation. XState v5 requires TypeScript 5.0+.

skill.md

XState v5 Skill

CRITICAL: This skill covers XState v5 ONLY. Do not use v4 patterns, APIs, or documentation. XState v5 requires TypeScript 5.0+.

When to Use

  • State machine and statechart design
  • Actor system implementation
  • XState v5 API usage (setup, createMachine, createActor)
  • Framework integration (React, Vue, Svelte)
  • Complex async flow orchestration

Key Concepts

Actors are independent entities that communicate by sending messages. XState v5 supports:

Actor Type Creator Use Case
State Machine createMachine() Complex state logic with transitions
Promise fromPromise() Async operations (fetch, timers)
Callback fromCallback() Bidirectional streams (WebSocket, EventSource)
Observable fromObservable() RxJS streams
Transition fromTransition() Reducer-like state updates

Quick Start

import { setup, assign, createActor } from 'xstate';

const machine = setup({
  types: {
    context: {} as { count: number },
    events: {} as { type: 'increment' } | { type: 'decrement' },
  },
  actions: {
    increment: assign({ count: ({ context }) => context.count + 1 }),
    decrement: assign({ count: ({ context }) => context.count - 1 }),
  },
}).createMachine({
  id: 'counter',
  initial: 'active',
  context: { count: 0 },
  states: {
    active: {
      on: {
        increment: { actions: 'increment' },
        decrement: { actions: 'decrement' },
      },
    },
  },
});

// Create and start actor
const actor = createActor(machine);
actor.subscribe((snapshot) => console.log(snapshot.context.count));
actor.start();
actor.send({ type: 'increment' });

v5 API Changes (NEVER use v4 patterns)

v4 (WRONG) v5 (CORRECT)
createMachine() alone setup().createMachine()
interpret() createActor()
service.start() actor.start()
state.matches() snapshot.matches()
services: {} actors: {}
state.context snapshot.context

Invoke vs Spawn

  • invoke: Actor lifecycle tied to state (created on entry, stopped on exit)
  • spawn: Dynamic actors independent of state transitions

Inspection API (Debugging)

const actor = createActor(machine, {
  inspect: (event) => {
    if (event.type === '@xstate.snapshot') {
      console.log(event.snapshot);
    }
  },
});

Event types: @xstate.actor, @xstate.event, @xstate.snapshot, @xstate.microstep

File Organization

feature/
├── feature.machine.ts    # Machine definition
├── feature.types.ts      # Shared types (optional)
├── feature.tsx           # React component
└── feature.test.ts       # Machine tests

Learning Path

Level Focus
Beginner Counter, toggle machines; setup() pattern
Intermediate Guards, actions, hierarchical states, fromPromise()
Advanced Observable actors, spawning, actor orchestration

Supporting Documentation

  • PATTERNS.md - Guards, actions, actors, hierarchical/parallel states
  • REACT.md - React hooks (useMachine, useActor, useSelector)
  • EXAMPLES.md - Complete working examples

Resources

general reviews

Ratings

4.572 reviews
  • Pratham Ware· Dec 28, 2024

    We added xstate from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.

  • Aanya Jackson· Dec 24, 2024

    Registry listing for xstate matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Mia Torres· Dec 20, 2024

    xstate fits our agent workflows well — practical, well scoped, and easy to wire into existing repos.

  • Chaitanya Patil· Dec 4, 2024

    xstate is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Aanya Kim· Dec 4, 2024

    Keeps context tight: xstate is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Hassan Ndlovu· Dec 4, 2024

    xstate reduced setup friction for our internal harness; good balance of opinion and flexibility.

  • Piyush G· Nov 23, 2024

    Keeps context tight: xstate is the kind of skill you can hand to a new teammate without a long onboarding doc.

  • Ava Rahman· Nov 23, 2024

    xstate is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.

  • Ishan Sanchez· Nov 23, 2024

    Registry listing for xstate matched our evaluation — installs cleanly and behaves as described in the markdown.

  • Benjamin Sharma· Nov 15, 2024

    Solid pick for teams standardizing on skills: xstate is focused, and the summary matches what you get after install.

showing 1-10 of 72

1 / 8