Workflow State Machine
Lightweight state machine for complex UI workflows. Visualizer included.
Overview
A state machine library that wraps XState with React-specific hooks and utilities, providing a more ergonomic API for common patterns like wizard flows, form submissions, and async operations. Includes a visual debugger that shows the current state, available transitions, and state history in real-time during development.
Motivation
XState is powerful but verbose for common patterns. Defining a 4-step wizard requires significant boilerplate. This library provides pre-built machine factories for the most common patterns: you define the states and transitions, not the XState scaffolding.
API
Visual Debugger
The debugger is a React DevTools extension that subscribes to machine state changes. It renders an interactive state diagram showing:
- Current active state (highlighted)
- Available transitions from the current state
- State history (last 20 transitions)
- Context diff between transitions
Performance was the main challenge for complex machines. The debugger uses a virtualized rendering approach: only draws visible portions of large state diagrams. A D3-based layout algorithm positions nodes; only nodes within the visible viewport are rendered as React components.
State Persistence
Tech Stack
TypeScript · XState · React · D3 (visualizer layout) · React DevTools Protocol · Vite