What XState Does
- Finite state machines — explicit states and transitions
- Statecharts — hierarchical, parallel, history states
- Actors — async, message-passing concurrency model
- Visualizer — Stately Studio for drag-and-drop editing
- Guards & actions — conditional transitions and side-effects
- Delayed transitions — timeouts without setTimeout juggling
- Model-based testing — auto-generate tests from machines
Architecture
A machine is a pure object describing states, events, transitions, and effects. createActor(machine) spawns a running instance. Actors can spawn child actors, creating a hierarchy. Works in any JS runtime; bindings exist for React, Vue, Svelte, Solid.
Self-Hosting
Client-side library. Stately Studio is a SaaS for visual editing (optional), but machines run anywhere.
Key Features
- Statecharts with hierarchy & parallel states
- Actor model for concurrency
- Fully type-safe (v5 uses
setup()for inference) - Visual editor (Stately Studio)
- Test generator (@xstate/test)
- Framework-agnostic core
- Bindings for React, Vue, Svelte, Solid
- SCXML export
Comparison
| Library | Paradigm | Complexity | Visual Tools |
|---|---|---|---|
| XState | Statecharts | Highest ceiling | Stately Studio |
| Zustand | Hooks store | Low | No |
| Redux | Reducers | Medium | Redux DevTools |
| MobX | Reactive | Medium | MobX DevTools |
FAQ
Q: When should I use XState? A: Complex UI flows (multi-step forms, payment flows, video players, collaborative editing). For simple global state, Zustand is enough.
Q: What is the Actor model? A: A concurrency model where each actor is an independent state machine that communicates via messages, avoiding race conditions from shared state.
Q: What changed in v5?
A: v5 introduces a setup() API for better TS type inference, simplifies the actor system, and replaces interpret with createActor.
Sources & Credits
- Docs: https://stately.ai/docs
- GitHub: https://github.com/statelyai/xstate
- License: MIT