# JavaScript state machine libraries

JavaScript state machine libraries model application logic as a fixed set of states and the events that move between them. A machine accepts only the transitions its definition allows rather than any combination of flags. These libraries keep checkout flows, UI components, and AI agent workflows in a known state at every step.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [@xstate/fsm](#xstate-fsm) | 38.7M | 30.5K | Jun 2023 | MIT |
| [XState](#xstate) | 31.2M | 30.5K | Nov 2026 | MIT |
| [machina](#machina) | 14.0M | 2.0K | Oct 2026 | MIT |
| [robot3](#robot) | 9.4M | 2.2K | Oct 2026 | BSD-2-Clause |
| [@zag-js/core](#zag-js-core) | 8.6M | 5.3K | Nov 2026 | MIT |
| [Finity](#finity) | 4.2M | 135 | Mar 2018 | MIT |
| [javascript-state-machine](#javascript-state-machine) | 1.1M | 8.7K | Jul 2018 | MIT |
| [Stately.js](#stately-js) | 70.4K | 814 | Oct 2017 | MIT |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[XState FSM](#xstate-fsm) has the most monthly downloads in this comparison, at 38.7M.

## Capabilities

| Library | Nested state models | Parallel state regions |
| --- | --- | --- |
| [@xstate/fsm](#xstate-fsm) | No | No |
| [XState](#xstate) | Yes | Yes |
| [machina](#machina) | Yes | No |
| [robot3](#robot) | Yes | No |
| [@zag-js/core](#zag-js-core) | Yes | No |
| [Finity](#finity) | Yes | No |
| [javascript-state-machine](#javascript-state-machine) | No | No |
| [Stately.js](#stately-js) | No | No |

## Libraries

### @xstate/fsm

[GitHub](https://github.com/statelyai/xstate) · [npm](https://www.npmjs.com/package/@xstate/fsm) · [Docs](https://cdn.jsdelivr.net/npm/@xstate/fsm@2.1.0/README.md)

Runs minimal finite state machines with the XState model.

- Downloads / mo: 38.7M
- Stars: 30.5K
- Last release: 2.1.0
- License: MIT
- Capabilities: [From the @xstate/fsm docs](https://cdn.jsdelivr.net/npm/@xstate/fsm@2.1.0/README.md)

```sh
npm install @xstate/fsm
```

**reach/reach-ui** (6.0K stars)

[reach/reach-ui](https://github.com/reach/reach-ui) 

```javascript
const getServiceState = <
	TContext extends object,
	TEvent extends MachineEvent = MachineEvent,
	TState extends Typestate<TContext> = any
>(
	service: StateMachine.Service<TContext, TEvent, TState>
): StateMachine.State<TContext, TEvent, TState> => {
	let currentValue: StateMachine.State<TContext, TEvent, TState>;
	service
		.subscribe((state) => {
			currentValue = state;
		})
		.unsubscribe();
	return currentValue!;
};

```

[packages/machine/src/reach-machine.ts](https://github.com/reach/reach-ui/blob/b3d94d22811db6b5c0f272b9a7e2e3c1bb4699ae/packages/machine/src/reach-machine.ts#L18-L32) · [More projects using @xstate/fsm →](https://dashboard.exa.ai/playground/search?q=%40xstate/fsm%20GitHub%20projects)

**Quickstart**

```javascript
import { createMachine } from '@xstate/fsm';

const machine = createMachine({
  initial: 'idle',
  states: { idle: { on: { START: 'running' } }, running: {} },
});
const nextState = machine.transition(machine.initialState, 'START');

```

From [README.md](https://cdn.jsdelivr.net/npm/@xstate/fsm@2.1.0/README.md)

### XState

[GitHub](https://github.com/statelyai/xstate) · [npm](https://www.npmjs.com/package/xstate) · [Docs](https://github.com/statelyai/xstate/blob/bd77717b8d33c49af1c8ee4a7e22cebb936cc8b1/README.md)

Models application logic with state machines, nested states, and actors.

- Downloads / mo: 31.2M
- Stars: 30.5K
- Last release: 5.33.4
- License: MIT
- Capabilities: [From the XState docs](https://github.com/statelyai/xstate/blob/bd77717b8d33c49af1c8ee4a7e22cebb936cc8b1/README.md)

**Strengths**

- **Groups behavior into nested states.** Use parent states to share behavior across related child states.
- **Manages asynchronous actor lifecycles.** Invoke actors when entering a state and stop them when leaving.

**Watch out for**

- **Async actions are not awaited.** Use invoked actors when the next state depends on asynchronous work.
- **Guards must be synchronous.** Finish asynchronous checks before sending the event that tests a guard.

```sh
npm install xstate
```

**processone/fluux-messenger** (450 stars)

[processone/fluux-messenger](https://github.com/processone/fluux-messenger) 

```typescript
private sendMachineEvent(event: ConnectionMachineEvent, source: string): void {
    const before = this.getMachineState()
    this.connectionActor.send(event)
    const after = this.getMachineState()
    const beforeText = JSON.stringify(before)
    const afterText = JSON.stringify(after)
    const message = `Machine event ${event.type} from ${source}: ${beforeText} -> ${afterText}`
    this.logTrace(message)
  }

```

[packages/fluux-sdk/src/core/modules/Connection.ts](https://github.com/processone/fluux-messenger/blob/583459002bde4f21cbb53a3556d81b7bf2a5b7c6/packages/fluux-sdk/src/core/modules/Connection.ts#L362-L370) · [More projects using XState →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20xstate%20for%20explicit%20state%20machines%2C%20transitions%2C%20guards%20and%20asynchronous%20effects&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
import { createMachine, createActor } from 'xstate';

const machine = createMachine({
  initial: 'idle',
  states: { idle: { on: { START: 'running' } }, running: {} },
});
const actor = createActor(machine).start();
actor.send({ type: 'START' });

```

From [README.md](https://github.com/statelyai/xstate/blob/bd77717b8d33c49af1c8ee4a7e22cebb936cc8b1/README.md)

### machina

[GitHub](https://github.com/ifandelse/machina.js) · [npm](https://www.npmjs.com/package/machina) · [Docs](https://github.com/ifandelse/machina.js/blob/c1bb667666e81054512f2bb64458ed4b239eee99/README.md)

Defines input-driven state machines and shared behaviors for independent client objects.

- Downloads / mo: 14.0M
- Stars: 2.0K
- Last release: 8.2.0
- License: MIT
- Capabilities: [From the machina docs](https://github.com/ifandelse/machina.js/blob/c1bb667666e81054512f2bb64458ed4b239eee99/README.md)

**Strengths**

- **Shares behavior across client objects.** Use createBehavioralFsm to track each client’s state independently.
- **Replays inputs after a transition.** Use defer() when an input arrives before the machine can handle it.

**Watch out for**

- **Async work needs completion events.** Start asynchronous work separately, then call handle() or transition() when finished.
- **Child handlers take priority.** Parent handlers run only when the child chain cannot handle an input.

```sh
npm install machina
```

**Quickstart**

```typescript
import { createFsm } from 'machina';

const machine = createFsm({
  id: 'task', initialState: 'idle', context: {},
  states: { idle: { START: 'running' }, running: {} },
});
machine.handle('START');

```

From [README.md](https://github.com/ifandelse/machina.js/blob/c1bb667666e81054512f2bb64458ed4b239eee99/README.md) · [Find projects using machina →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20machina%20for%20explicit%20state%20machines%2C%20transitions%2C%20guards%20and%20asynchronous%20effects&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### robot3

[GitHub](https://github.com/matthewp/robot) · [npm](https://www.npmjs.com/package/robot3) · [Docs](https://github.com/matthewp/robot/blob/4ed41e00e4c4a70d595a647e57585e44d73c83ce/docs/src/content/docs/interpret.md)

Composes immutable state-machine definitions from state, transition, guard, and invocation functions.

- Downloads / mo: 9.4M
- Stars: 2.2K
- Last release: 1.4.0
- License: BSD-2-Clause
- Capabilities: [From the robot3 docs](https://github.com/matthewp/robot/blob/4ed41e00e4c4a70d595a647e57585e44d73c83ce/docs/src/content/docs/interpret.md)

**Strengths**

- **Composes nested machines through invocation.** Invoke a child machine from a parent state.
- **Routes promise outcomes into events.** Handle done and error transitions from invoked promise-returning functions.

**Watch out for**

- **Leaving a state discards results.** Results are ignored after leaving their invoking state.

```sh
npm install robot3
```

**fal-ai/fal-js** (189 stars)

[fal-ai/fal-js](https://github.com/fal-ai/fal-js) 

```typescript
export function createRealtimeClient({
  config,
}: RealtimeClientDependencies): RealtimeClient {
  return {
    connect<Input, Output>(
      app: string,
      handler: RealtimeConnectionHandler<Output>,
    ): RealtimeConnection<Input> {
      const {
        // if running on React in the server, set clientOnly to true by default
        clientOnly = isReact() && !isBrowser(),
        connectionKey = crypto.randomUUID(),
        maxBuffering,
        path,
        throttleInterval = DEFAULT_THROTTLE_INTERVAL,
        encodeMessage: encodeMessageOverride,
        decodeMessage: decodeMessageOverride,
        tokenProvider,
        tokenExpirationSeconds,
      } = handler;
      if (clientOnly && !isBrowser()) {
        return NoOpConnection;
      }

      const encodeMessageFn =
        encodeMessageOverride ?? ((input: any) => encodeRealtimeMessage(input));
      const decodeMessageFn =
        decodeMessageOverride ?? ((data: any) => decodeRealtimeMessage(data));

      let previousState: string | undefined;
      let latestEnqueuedMessage: any;
      let tokenRefreshTimer: ReturnType<typeof setTimeout> | undefined;
      let tokenRefreshGeneration = 0;

      // Although the state machine is cached so we don't open multiple connections,
      // we still need to update the callbacks so we can call the correct references
      // when the state machine is reused. This is needed because the callbacks
      // are passed as part of the handler object, which can be different across
      // different calls to `connect`.
      connectionCallbacks.set(connectionKey, {
        decodeMessage: decodeMessageFn,
        onError: handler.onError,
        onResult: handler.onResult,
      });
      const getCallbacks = () =>
        connectionCallbacks.get(connectionKey) as RealtimeConnectionCallback;
      const stateMachine = reuseInterpreter(
        connectionKey,
        throttleInterval,
        ({ context, machine, send }) => {
          const { enqueuedMessage, token, websocket } = context;
          latestEnqueuedMessage = enqueuedMessage;
          if (
            machine.current === "active" &&
            enqueuedMessage &&
            websocket?.readyState === WebSocket.OPEN
          ) {
            send({ type: "send", message: enqueuedMessage });
          }
          if (
            machine.current === "authRequired" &&
            token === undefined &&
            previousState !== machine.current
          ) {
            send({ type: "initiateAuth" });
            tokenRefreshGeneration++;
            const generation = tokenRefreshGeneration;
            // Use custom tokenProvider if provided, otherwise use default
            const appId = ensureEndpointIdFormat(app);
            const resolvedPath =
              resolveEndpointPath(app, path, "/realtime") ?? "";
            const fetchToken = tokenProvider
              ? () => tokenProvider(`${appId}${resolvedPath}`)
              : () => {
                  console.warn(
                    "[fal.realtime] Using the default token provider is deprecated. " +
                      "Please provide a `tokenProvider` function to `fal.realtime.connect()`. " +
                      "See https://docs.fal.ai/model-apis/client#client-side-usage-with-token-provider for more information.",
                  );
                  return getTemporaryAuthToken(app, config);
                };

            const effectiveExpiration = tokenProvider
              ? tokenExpirationSeconds
              : TOKEN_EXPIRATION_SECONDS;

            const scheduleTokenRefresh =
              effectiveExpiration !== undefined
                ? () => {
                    clearTimeout(tokenRefreshTimer);
                    const refreshMs = Math.round(
                      effectiveExpiration * 0.9 * 1000,
                    );
                    tokenRefreshTimer = setTimeout(() => {
                      if (generation !== tokenRefreshGeneration) {
                        return;
                      }
                      fetchToken()
                        .then((newToken) => {
                          if (generation !== tokenRefreshGeneration) {
                            return;
                          }
                          queueMicrotask(() => {
                            send({ type: "authenticated", token: newToken });
                          });
                          scheduleTokenRefresh();
                        })
                        .catch(() => {
                          if (generation !== tokenRefreshGeneration) {
                            return;
                          }
                          const retryMs = Math.round(
                            effectiveExpiration * 0.05 * 1000,
                          );
                          tokenRefreshTimer = setTimeout(() => {
                            scheduleTokenRefresh();
                          }, retryMs);
                        });
                    }, refreshMs);
                  }
                : noop;

            fetchToken()
              .then((token) => {
                queueMicrotask(() => {
                  send({ type: "authenticated", token });
                });
                scheduleTokenRefresh();
              })
              .catch((error) => {
                queueMicrotask(() => {
                  send({ type: "unauthorized", error });
                });
              });
          }
          if (
            machine.current === "connecting" &&
            previousState !== machine.current &&
            token !== undefined
          ) {
            const ws = new WebSocket(
              buildRealtimeUrl(app, { token, maxBuffering, path }),
            );
            ws.onopen = () => {
              send({ type: "connected", websocket: ws });
              const queued =
                stateMachine.service.context?.enqueuedMessage ??
                latestEnqueuedMessage;
              if (queued) {
                ws.send(encodeMessageFn(queued));
                stateMachine.service.context = {
                  ...stateMachine.service.context,
                  enqueuedMessage: undefined,
                };
              }
            };
            ws.onclose = (event) => {
              if (event.code !== WebSocketErrorCodes.NORMAL_CLOSURE) {
                const { onError = noop } = getCallbacks();
                onError(
                  new ApiError({
                    message: `Error closing the connection: ${event.reason}`,
                    status: event.code,
                  }),
                );
              }
              send({ type: "connectionClosed", code: event.code });
            };
            ws.onerror = (event) => {
              // TODO specify error protocol for identified errors
              const { onError = noop } = getCallbacks();
              onError(new ApiError({ message: "Unknown error", status: 500 }));
            };
            ws.onmessage = (event) => {
              const {
                decodeMessage = decodeMessageFn,
                onResult,
                onError = noop,
              } = getCallbacks();

              handleRealtimeMessage({
                data: event.data,
                decodeMessage,
                onResult,
                onError,
                send,
              });
            };
          }
          if (previousState === "active" && machine.current !== "active") {
            clearTimeout(tokenRefreshTimer);
            tokenRefreshTimer = undefined;
          }
          previousState = machine.current;
        },
      );

      const send = (input: Input & Partial<WithRequestId>) => {
        // Use throttled send to avoid sending too many messages
        stateMachine.throttledSend({
          type: "send",
          message: encodeMessageFn(input),
        });
      };

      const close = () => {
        stateMachine.service.send({ type: "close" });
      };

      return {
        send,
        close,
      };
    },
  };
}

```

[libs/client/src/realtime.ts](https://github.com/fal-ai/fal-js/blob/153ed5697302866752d20c205a85030d929ed48c/libs/client/src/realtime.ts#L513-L728) · [More projects using robot3 →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20robot3%20for%20explicit%20state%20machines%2C%20transitions%2C%20guards%20and%20asynchronous%20effects&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
import { createMachine, interpret, state, transition } from 'robot3';

const machine = createMachine({
  idle: state(transition('START', 'running')),
  running: state(),
});
const service = interpret(machine, () => {});
service.send('START');

```

From [interpret.md](https://github.com/matthewp/robot/blob/4ed41e00e4c4a70d595a647e57585e44d73c83ce/docs/src/content/docs/interpret.md)

### @zag-js/core

[GitHub](https://github.com/chakra-ui/zag) · [npm](https://www.npmjs.com/package/@zag-js/core) · [Docs](https://cdn.jsdelivr.net/npm/@zag-js/core@1.48.0/dist/index.d.ts)

Implements a minimal XState FSM for UI machines.

- Downloads / mo: 8.6M
- Stars: 5.3K
- Last release: 1.48.0
- License: MIT
- Capabilities: [From the @zag-js/core docs](https://cdn.jsdelivr.net/npm/@zag-js/core@1.48.0/dist/index.d.ts)

```sh
npm install @zag-js/core
```

**Quickstart**

```javascript
import { createMachine, findTransition } from '@zag-js/core';

const machine = createMachine({
  initialState: () => 'idle',
  states: { idle: { on: { START: { target: 'running' } } }, running: {} },
});
const match = findTransition(machine, 'idle', 'START');

```

From [state.d.ts](https://cdn.jsdelivr.net/npm/@zag-js/core@1.48.0/dist/index.d.ts) · [Find projects using @zag-js/core →](https://dashboard.exa.ai/playground/search?q=%40zag-js/core%20GitHub%20projects)

### Finity

[GitHub](https://github.com/nickuraltsev/finity) · [npm](https://www.npmjs.com/package/finity) · [Docs](https://github.com/nickuraltsev/finity/blob/master/README.md)

Defines finite state machines for Node.js and the browser through a configuration DSL.

- Downloads / mo: 4.2M
- Stars: 135
- Last release: 0.5.4
- License: MIT
- Capabilities: [From the Finity docs](https://github.com/nickuraltsev/finity/blob/master/README.md)

```sh
npm install finity
```

**slackapi/node-slack-sdk** (3.4K stars)

[slackapi/node-slack-sdk](https://github.com/slackapi/node-slack-sdk) 

```javascript
private onWebsocketMessage(data: WebSocket.RawData): void {
  this.logger.debug(`received message on websocket: ${data.toString()}`);

  // parse message into slack event
  let event: { type: string } & Record<string, unknown>;
  try {
    event = JSON.parse(data.toString());
    // biome-ignore lint/suspicious/noExplicitAny: errors can be anything
  } catch (parseError: any) {
    // prevent application from crashing on a bad message, but log an error to bring attention
    this.logger.error(
      `unable to parse incoming websocket message: ${parseError.message}\n    message contents: "${data}"`,
    );
    return;
  }

  // internal event handlers
  if (event.type === 'hello') {
    this.stateMachine.handle('server hello');
  }
  if (event.type === 'team_migration_started') {
    if (this.websocket !== undefined) {
      // this will trigger the 'websocket close' event on the state machine, which transitions to clean up
      this.websocket.close();
    }
  }

  if (
    this.stateMachine.getCurrentState() === 'connected' &&
    this.stateMachine.getStateHierarchy()[1] === 'resuming' &&
    event.reply_to !== undefined &&
    event.reply_to === this.messageId
  ) {
    this.stateMachine.handle('replay finished');
  }

  // emit for event handlers
  this.emit('slack_event', event.type, event);
  this.emit(event.type, event);
  if (event.subtype !== undefined) {
    this.emit(`${event.type}::${event.subtype}`, event);
  }
}

```

[packages/rtm-api/src/RTMClient.ts](https://github.com/slackapi/node-slack-sdk/blob/881ca7b345abf6ce2977931f2d26059159127e09/packages/rtm-api/src/RTMClient.ts#L663-L705) · [More projects using Finity →](https://dashboard.exa.ai/playground/search?q=finity%20GitHub%20projects)

**Quickstart**

```javascript
import Finity from 'finity';

const machine = Finity.configure()
  .initialState('idle').on('START').transitionTo('running')
  .state('running').start();
machine.handle('START');

```

From [README.md](https://github.com/nickuraltsev/finity/blob/master/README.md)

### javascript-state-machine

[GitHub](https://github.com/jakesgordon/javascript-state-machine) · [npm](https://www.npmjs.com/package/javascript-state-machine) · [Docs](https://github.com/jakesgordon/javascript-state-machine/blob/0d603577423244228cebcd62e60dbbfff27c6ea3/README.md)

Defines named states and transitions with generated transition methods and lifecycle observers.

- Downloads / mo: 1.1M
- Stars: 8.7K
- Last release: 3.1.0
- License: MIT
- Capabilities: [From the javascript-state-machine docs](https://github.com/jakesgordon/javascript-state-machine/blob/0d603577423244228cebcd62e60dbbfff27c6ea3/README.md)

**Strengths**

- **Observes transition lifecycle events.** Attach observers before transitions, during state changes, or after completion.
- **Pauses transitions for promises.** Return a promise from a lifecycle observer to delay transition completion.

**Watch out for**

- **Pending transitions reject overlapping triggers.** Wait for a pending transition or handle onPendingTransition explicitly.
- **Unsettled promises block the machine.** Resolve or reject every promise returned from a transition observer.

```sh
npm install javascript-state-machine
```

**dashersw/brain-bits** (186 stars)

[dashersw/brain-bits](https://github.com/dashersw/brain-bits) 

```typescript
onCountdown() {
                    (function tick() {
                        session._display(session.countdownMessages.shift());

                        if (!session.countdown--) {
                            session.fsm.run();
                        } else {
                            setTimeout(tick, 1000);
                        }
                    }());
                }

```

[src/models/session/live-session.js](https://github.com/dashersw/brain-bits/blob/2da52e7162ed844eea4a149f274a838661d1f216/src/models/session/live-session.js#L24-L34) · [More projects using javascript-state-machine →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20javascript-state-machine%20for%20explicit%20state%20machines%2C%20transitions%2C%20guards%20and%20asynchronous%20effects&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```typescript
const StateMachine = require('javascript-state-machine');

const machine = new StateMachine({
  init: 'idle',
  transitions: [{ name: 'start', from: 'idle', to: 'running' }],
});
machine.start();

```

From [README.md](https://github.com/jakesgordon/javascript-state-machine/blob/0d603577423244228cebcd62e60dbbfff27c6ea3/README.md)

### Stately.js

[GitHub](https://github.com/fschaefer/Stately.js) · [npm](https://www.npmjs.com/package/stately.js) · [Docs](https://github.com/fschaefer/Stately.js/blob/master/README.md)

Runs finite state machines in Node.js and the browser.

- Downloads / mo: 70.4K
- Stars: 814
- Last release: 2.0.0
- License: MIT
- Capabilities: [From the Stately.js docs](https://github.com/fschaefer/Stately.js/blob/master/README.md)

```sh
npm install stately.js
```

**noodlefrenzy/node-amqp10** (134 stars)

[noodlefrenzy/node-amqp10](https://github.com/noodlefrenzy/node-amqp10) 

```javascript
var detachHandler = function(frame) {
  if (this.getMachineState() === 'ATTACHED') {
    this.ATTACHED.sendDetach({ closed: frame.closed });
  }

  link._detached(frame);
  return this.DETACHED;
};

```

[lib/link.js](https://github.com/noodlefrenzy/node-amqp10/blob/f5c2aa570830a8dd454e89ed3f4222fc7953fcf7/lib/link.js#L16-L23) · [More projects using Stately.js →](https://dashboard.exa.ai/playground/search?q=stately.js%20GitHub%20projects)

**Quickstart**

```javascript
const Stately = require('stately.js');

const machine = new Stately({
  idle: { START: 'running' },
  running: {},
}, 'idle');
machine.START();

```

From [README.md](https://github.com/fschaefer/Stately.js/blob/master/README.md)

## FAQ

### Which JavaScript state machine library should I use?

[XState](#xstate) suits apps that need nested and parallel states with an actor model. [XState FSM](#xstate-fsm) suits apps that need a minimal flat state machine. [Robot](#robot) suits code that prefers functional, immutable machine definitions.

### What is a state machine?

A state machine is a model with a finite set of states, where each event moves the system from one state to another by a defined transition. Only one state is active at a time in a flat machine.

### What are statecharts?

Statecharts extend state machines with nested states, parallel regions, and history. [XState](#xstate) implements full statecharts. [XState FSM](#xstate-fsm) leaves those features out.

### What is XState?

[XState](#xstate) models application logic with state machines, statecharts, and actors. It supports nested and parallel state configurations.

### What is Zag?

[Zag core](#zag-js-core) is the state machine core behind the Zag UI component machines. It implements a minimal version of the XState FSM model for UI components.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript state machine libraries XState javascript-state-machine Robot machina code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
