xstate

Design, test, and diagram typed XState 5 actor lifecycles for React applications.

3|Updated Nov 8, 2014
One-click install
npx skills add https://github.com/mintuz/.dotfiles --skill xstate-mintuz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: xstate
Source: https://github.com/mintuz/.dotfiles/tree/main/agents/.agents/skills/xstate
Command: npx skills add https://github.com/mintuz/.dotfiles --skill xstate-mintuz

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires xstate, @xstate/react, mermaid, and includes references (resource) components.

What problem does it solve? Hand-rolled React state — loading flags, retry timers, cancellation guards, and stale async responses — scatters lifecycle logic across useState and useEffect, producing race conditions and leaked resources. This Skill models those temporal concerns as explicit XState 5 statecharts with clear ownership of effects, retries, and resource lifetimes. ## Core Features & Use Cases - Lifecycle modelling: Converts implicit async state (isSubmitting flags, polling timers, gesture handling) into typed actor machines with factories, injected ports, and discriminated event unions. - React integration: Structures @xstate/react usage with route-owned useActorRef, focused selectors, and clear rules for what stays in useState versus the machine. - Testing and diagramming: Drives real actors with fake ports to prove retries, cancellation, and exactly-once teardown, and renders legal Mermaid stateDiagram-v2 charts for every machine. - Use Case: When a form submission needs loading state, retries with backoff, cancellation, and protection against stale responses, use this Skill to design the actor machine, wire it into React, write boundary tests, and generate the statechart diagram. ## Quick Start Use the xstate skill to model this form submission flow — with loading, retry, and cancellation — as an XState 5 machine integrated with React.

Frequently Asked Questions about xstate

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage async loading and retry state in React with XState?

Model the async work as an invoked actor inside a lifecycle state, keep retry count and backoff delays in the machine, and fence results by attempt identity. The machine owns isSubmitting-style flags instead of useState, so cancellation and stale responses are handled structurally.

When should I use XState instead of useState in React?

Use XState when state changes in response to an external answer — network responses, timers, other actors — or when an interaction has an interruptible middle like a drag. Keep useState only for values one event sets completely, such as text drafts or simple open/closed toggles.

How do I test XState actors and machines?

Create real actors from production factories with fake IDs, clocks, and transports, then send typed public events and assert public states and emitted commands. Cover negative space like stale identities and late results, and prove teardown by counting unsubscribe or close calls.

Does this Skill support XState 4 and XState 5?

The Skill targets XState 5 and @xstate/react APIs such as setup, fromPromise, fromCallback, and useActorRef. It instructs checking the installed major version first, since XState 4 and 5 APIs differ significantly.

How do I generate a state diagram from an XState machine?

Trace each createMachine definition and render it as a Mermaid stateDiagram-v2 chart, mapping initial states, finals, guards, parallel regions, and invokes to legal Mermaid syntax. Validate with a renderer or parser and report the exact validation method used.

Why do stale async responses still update my XState machine after cancellation?

Stopping an actor ignores its future outcome but does not retract events already sent to the parent or abort work in ports without signal support. Fence results by attempt or generation identity so late results from replaced attempts are rejected by guards.