sablier-labs/agent-skills/xstate-react
- community
Checking that the SKILL.md file is still in the repository.
This skill should be used when the user asks to "create a state machine", "add xState", "use xState with React", "implement actor-based state", "manage complex state with state machines", "use xState with Effect", "integrate Effect-ts with xState", mentions xState hooks (useMachine, useActor, useSelector), or discusses finite state machines in React applications.
Install
npx vskill@latest install sablier-labs/agent-skills/xstate-reactSKILL.md
xState React
Your Role
You are an expert in xState v5 actor-based state management with React and TypeScript. You understand state machines, statecharts, the actor model, and React integration patterns for managing complex application logic.
Overview
xState is an actor-based state management and orchestration solution for JavaScript and TypeScript applications. It uses event-driven programming, state machines, statecharts, and the actor model to handle complex logic in predictable, robust, and visual ways.
When to use xState:
- Complex UI flows (multi-step forms, wizards, checkout processes)
- State with many transitions and edge cases
- Logic that needs to be visualized and validated
- Processes with async operations and error handling
- State that can be in multiple "modes" (loading, error, success, idle)
When to use simpler state instead (useState, Zustand):
- Simple UI toggles and counters
- Form state confined to a single component
- State without complex transition logic
- CRUD operations with straightforward loading states
Quick Start
Create a state machine and use it in a React component:
React Hooks API
useMachine
Create and run a machine within a component's lifecycle:
useActor
Subscribe to an existing actor (created outside the component):
useSelector
Optimize re-renders by selecting specific state:
TypeScript Patterns
Typing Machines with types
Define context and events using the types property:
Using setup() for Reusable Definitions
Define actions, guards, actors, and delays in a type-safe way:
Core Concepts
States and Transitions
States represent the possible modes of your system. Transitions define how events move between states:
Context
Context holds extended state data:
Actions
Actions are fire-and-forget side effects:
Best Practices
DO
- Use
setup()for type-safe action and guard definitions - Use
useSelectorfor optimized state selection - Define explicit types for context and events
- Use
state.matches()for hierarchical state checking - Keep machines pure and side-effect-free (use actions for effects)
DON'T
- Don't store the entire snapshot object in React state
- Don't mutate context directly (use
assign) - Don't use xState for simple toggle/counter state
- Don't forget to handle all possible states in your UI
Client Component Requirement
xState hooks must be used in Client Components. Add the "use client" directive:
Additional Documentation
For comprehensive xState documentation including advanced patterns, use the Context7 MCP:
See `./references/patterns.md` for common patterns including async operations, guards, parallel states, and persistence.
Quick Reference
| Task | Pattern | |
|---|---|---|
| Create machine | createMachine({ id, initial, states, context }) | |
| Use in component | const [state, send] = useMachine(machine) | |
| Check state | state.matches("loading") or state.value | |
| Send event | send({ type: "EVENT_NAME", ...payload }) | |
| Read context | state.context.someValue | |
| Update context | assign({ key: ({ context, event }) => newValue }) | |
| Conditional | guard: "guardName" or guard: ({ context }) => … | |
| Async operation | invoke: { src: fromPromise(...), onDone, onError } | |
| Optimized select | useSelector(actorRef, (state) => state.context.x) |
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/xstate-react/SKILL.md
Popularity
- Repository stars
- 6
- Repository forks
- 1
- 7-day trend score
- 10
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 16 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/sablier-labs/agent-skills/xstate-react)