react-state-machine

react-state-machine is a skill for Claude Code from bobmatnyc/claude-mpm-skills. It costs 19 tokens per session (1,902 once invoked), scanned A, original, MIT.

A guide to modeling complex React interface behavior as explicit states, events, and transitions with XState v5. It also uses the actor model, where each independent process has its own lifecycle.

In plain words
What is it for?
Use it to design reusable state machines for React features with complex behavior, such as async requests, multi-step forms, and coordinated timing. It is not intended for simple toggles, counters, basic validation, or server-data caching.
Why use it?
It helps prevent contradictory combinations such as loading, error, and success all being true at once. It also clarifies timeouts, delays, debouncing, and dependencies between interface states.

Skill for Claude Code

Written for Claude Code: disable-model-invocation in frontmatter.

Good fit Use it to design reusable state machines for React features with complex behavior, such as async requests, multi-step forms, and coordinated timing. It is not intended for simple toggles, counters, basic validation, or server-data caching.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/bobmatnyc/claude-mpm-skills/react-state-machine
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add bobmatnyc/claude-mpm-skills --skill react-state-machine
Clone the repo
git clone --depth 1 https://github.com/bobmatnyc/claude-mpm-skills

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for react-state-machine

README.md
[![agentmods](https://agentmods.dev/badge/skills/bobmatnyc/claude-mpm-skills/react-state-machine/github.svg)](https://agentmods.dev/skills/bobmatnyc/claude-mpm-skills/react-state-machine)
Your own site
<a href="https://agentmods.dev/skills/bobmatnyc/claude-mpm-skills/react-state-machine"><img src="https://agentmods.dev/badge/skills/bobmatnyc/claude-mpm-skills/react-state-machine/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for react-state-machine

Your own site · 80×15
<a href="https://agentmods.dev/skills/bobmatnyc/claude-mpm-skills/react-state-machine"><img src="https://agentmods.dev/badge/skills/bobmatnyc/claude-mpm-skills/react-state-machine.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 19 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,902 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector pass 7 Sept 2026
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00019 $0.01902
Opus 5 $0.00010 $0.00951
Sonnet 5 $0.00004 $0.00380
Haiku 4.5 $0.00002 $0.00190

Measured 9d ago against content hash 431b983be390, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

react-state-machine scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

toolchains/javascript/frameworks/react/react-state-machine/SKILL.md · 214 lines

How it starts

The opening of the file, as written. The whole thing — 214 lines — stays where its author put it; the contents beside it link to each section on GitHub.

React State Machines with XState v5

Overview

State machines make impossible states unrepresentable by modeling UI behavior as explicit states, transitions, and events. XState v5 (2.5M+ weekly npm downloads) unifies state machines with the actor model—every machine is an independent entity with its own lifecycle, enabling sophisticated composition patterns.

When to Use This Skill

Trigger patterns:

  • Boolean flag explosion: multiple isLoading, isError, isSuccess flags
  • Implicit states: writing if (isLoading && !isError && data) to derive mode
  • Defensive coding: guards before state updates to prevent invalid transitions
  • Timing coordination: timeouts, delays, debouncing across states
  • State dependencies: one state depends on another to update correctly

Do not use for:

  • Simple boolean toggles with no async (useState is simpler)
  • Single form fields with basic validation (useReducer suffices)
  • Server state caching (React Query/TanStack Query handles this)
  • Static data transformations (useMemo is better)
  • Simple counters or toggles (useState is clearer)

See decision-trees.md for comprehensive decision guidance

Core Mental Model

Finite states represent modes of behavior: idle, loading, success, error. A component can only be in ONE state at a time.

Context (extended state) stores quantitative data that doesn't define distinct states. The finite state says "playing"; context says what at what volume.

Events trigger transitions between states. Events are objects: { type: 'SUBMIT', data: formData }.

Guards conditionally allow/block transitions: { guard: 'hasValidInput' }.

Actions are fire-and-forget side effects during transitions or state entry/exit.

Invoked actors are long-running processes (API calls, subscriptions) with lifecycle management and cleanup.

Quick Start: XState v5 setup() Pattern

import { setup, assign, fromPromise } from 'xstate';

const fetchMachine = setup({
  types: {
    context: {} as { data: User | null; error: string | null },
    events: {} as 
      | { type: 'FETCH'; userId: string }
      | { type: 'RETRY' }
  },
  actors: {
    fetchUser: fromPromise(async ({ input, signal }) => {
      const res = await fetch(`/api/users/${input.userId}`, { signal });
      if (!res.ok) throw new Error(res.statusText);
      return res.json();
    })
  },
  actions: {
    setData: assign({ data: ({ event }) => event.output }),
    setError: assign({ error: ({ event }) => event.error.message })
  }
}).createMachine({
  id: 'fetch',
  initial: 'idle',
  context: { data: null, error: null },
  states: {
    idle: { on: { FETCH: 'loading' } },
    loading: {
      invoke: {
        src: 'fetchUser',
        input: ({ event }) => ({ userId: event.userId }),
        onDone: { target: 'success', actions: 'setData' },
        onError: { target: 'failure', actions: 'setError' }
      }
    },
    success: { on: { FETCH: 'loading' } },
    failure: { on: { RETRY: 'loading' } }
  }
});

Read the full file on GitHub · 214 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 214 lines · 19 tokens per session scan A 431b983be390

Subscribe to this mod's changes

react-state-machine is a skill published in the GitHub repository bobmatnyc/claude-mpm-skills (74 stars, last pushed 1mo ago), licensed MIT. It adds 19 tokens to every session and 1,902 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.