Design, implement, review, and migrate XState v5 state machines and statecharts in TypeScript using modern v5 patterns. Use this whenever the user mentions XState, actors, state machines, statecharts, guards, transitions, workflows, or Stately, or is modeling non-trivial UI/app/process logic in a codebase that uses XState. Prefer a short machine sketch before code when requirements are fuzzy. If the problem is too simple for a state machine, say so and recommend @xstate/store instead.
91%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Use this reference when the task involves any of these:
fromObservable(...) or RxJS-backed actorsPrefer fromObservable(...) when the actor naturally wraps a stream of values from an observable source.
Use it when:
Prefer fromCallback(...) instead when the source is a callback/listener API rather than an observable.
Reference anchor:
fromObservable(...) example: xstate core changelogMinimal shape:
import { createActor, fromObservable } from 'xstate';
import { interval } from 'rxjs';
type Output = number;
type Input = { period?: number };
const tickerLogic = fromObservable<Output, Input>(({ input }) => {
return interval(input.period ?? 1000);
});
const actor = createActor(tickerLogic, {
input: { period: 500 }
});When debugging actor systems programmatically, use actor.system.inspect(...).
This is useful when:
It accepts either a function or an observer and returns a subscription.
Reference anchor:
actor.system.inspect(...) usage and unsubscribe behavior: inspect testMinimal shape:
import { createActor, createMachine } from 'xstate';
const actor = createActor(createMachine({}));
const sub = actor.system.inspect((inspectionEvent) => {
console.log(inspectionEvent.type);
});
actor.start();
sub.unsubscribe();When the user wants visual debugging in an app, prefer @statelyai/inspect with createBrowserInspector(...).
Reference anchor:
Minimal shape:
import { useMachine } from '@xstate/react';
import { createBrowserInspector } from '@statelyai/inspect';
import { feedbackMachine } from './feedbackMachine';
const { inspect } = createBrowserInspector({
autoStart: false
});
export function Feedback() {
const [snapshot, send] = useMachine(feedbackMachine, {
inspect
});
return (
<button onClick={() => send({ type: 'restart' })}>
{snapshot.matches('closed') ? 'Restart' : 'Send'}
</button>
);
}fromPromise(...): one request, one resultfromCallback(...): callback/listener protocol, many eventsfromObservable(...): real observable streamactor.system.inspect(...): programmatic visibilitycreateBrowserInspector(...): visual/debug UI visibility