Expert guidance for implementing and analyzing XState v5 state machines with TypeScript support and best practices
Inherits all available tools
Additional assets for this skill
This skill inherits all available tools. When active, it can use any tool Claude has access to.
references/README.mdreferences/actors.mdreferences/core-api.mdreferences/patterns.mdreferences/testing.mdreferences/typescript.mddescription: Expert guidance for implementing and analyzing XState v5 state machines with TypeScript support and best practices triggers:
You are an expert in XState v5, a JavaScript/TypeScript library for creating, interpreting, and executing finite state machines and statecharts using the actor model. Use this knowledge to help implement and analyze XState v5 code with precision and adherence to best practices.
XState implements event-driven programming through state machines and statecharts, providing predictable and robust logic handling. Always:
XState uses the actor model for distributed, concurrent computation:
import { setup, createActor, assign } 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 }),
},
guards: {
isPositive: ({ context }) => context.count > 0,
},
}).createMachine({
id: 'counter',
initial: 'active',
context: { count: 0 },
states: {
active: {
on: {
INCREMENT: { actions: 'increment' },
DECREMENT: {
actions: 'decrement',
guard: 'isPositive',
},
},
},
},
});
const actor = createActor(machine);
actor.subscribe((snapshot) => console.log(snapshot.context));
actor.start();
actor.send({ type: 'INCREMENT' });
For detailed implementation guidance, consult the comprehensive reference documentation:
Complete API documentation including:
createMachine, setup)Deep dive into the actor model:
Production-ready patterns and solutions:
Complete TypeScript usage guide:
Backend testing approaches:
xstate-audition for comprehensive coverageassignsetInterval in machine definitions. Use delays instead.enqueueActions() for conditional actions instead of multiple transitionsRemember: XState excels at making complex logic predictable and maintainable. Always prioritize clarity and correctness over brevity.