# @xstate/react

> XState tools for React

Latest version **6.1.0** (published 2026-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @xstate/react
pnpm add @xstate/react
yarn add @xstate/react
bun add @xstate/react
```

## Health

**Score 70/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; popular repo.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.1.0 |
| Published | 2026-02-26 |
| First published | 2019-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 37.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 30125 |
| Author | David Khourshid |
| Maintainers | davidkpiano, andarist |
| Keywords | state, machine, statechart, scxml, state, graph, react, hook |

## Links

- npm: https://www.npmjs.com/package/@xstate/react
- Repository: https://github.com/statelyai/xstate
- Homepage: https://github.com/statelyai/xstate/tree/main/packages/xstate-react#readme
- Issues: https://github.com/statelyai/xstate/issues
- npm.io page: https://npm.io/package/@xstate/react

## Dependencies (2)

- [use-sync-external-store](https://npm.io/package/use-sync-external-store.md) ^1.2.0
- [use-isomorphic-layout-effect](https://npm.io/package/use-isomorphic-layout-effect.md) ^1.1.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 6.1.0 (latest) — 2026-02-26
- 7.0.0-alpha.2 (alpha) — 2026-09-03
- 4.0.0-beta.12 (beta) — 2023-12-01
- 7.0.0-alpha.1 — 2026-06-20
- 6.0.0 — 2025-06-19
- 5.0.5 — 2025-05-31
- 5.0.4 — 2025-05-12
- 5.0.3 — 2025-03-10
- 5.0.2 — 2025-01-12
- 5.0.1 — 2024-12-24
- 5.0.0 — 2024-11-12
- 4.1.3 — 2024-09-21
- 4.1.2 — 2024-09-06
- 4.1.1 — 2024-04-17
- 4.1.0 — 2024-02-12
- … 73 more at https://npm.io/package/@xstate/react/versions

## README

# @xstate/react

This package contains utilities for using [XState](https://github.com/statelyai/xstate) with [React](https://github.com/facebook/react/).

- [Read the full documentation in the XState docs](https://stately.ai/docs/xstate-react).
- [Read our contribution guidelines](https://github.com/statelyai/xstate/blob/main/CONTRIBUTING.md).

## Quick start

1. Install `xstate` and `@xstate/react`:

```bash
npm i xstate @xstate/react
```

2. Import the `useMachine` hook:

```tsx
import { useMachine } from '@xstate/react';
import { createMachine } from 'xstate';

const toggleMachine = createMachine({
  id: 'toggle',
  initial: 'inactive',
  states: {
    inactive: {
      on: { TOGGLE: 'active' }
    },
    active: {
      on: { TOGGLE: 'inactive' }
    }
  }
});

export const Toggler = () => {
  const [state, send] = useMachine(toggleMachine);

  return (
    <button onClick={() => send({ type: 'TOGGLE' })}>
      {state.value === 'inactive'
        ? 'Click to activate'
        : 'Active! Click to deactivate'}
    </button>
  );
};
```

---
_Source: https://npm.io/package/@xstate/react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
