# @volue/react-states

> Explicit states for predictable user experiences

Latest version **7.3.0** (published 2025-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @volue/react-states
pnpm add @volue/react-states
yarn add @volue/react-states
bun add @volue/react-states
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.3.0 |
| Published | 2025-10-17 |
| First published | 2023-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 245.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 142 |
| Author | Christian Alfoni |
| Maintainers | fima1, it.management |
| Keywords | typescript, react, reducer, state, statemachine |

## Links

- npm: https://www.npmjs.com/package/@volue/react-states
- Repository: https://github.com/christianalfoni/react-states
- Homepage: https://github.com/christianalfoni/react-states#readme
- Issues: https://github.com/christianalfoni/react-states/issues
- npm.io page: https://npm.io/package/@volue/react-states

## 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

- 7.3.0 (latest) — 2025-10-17
- 7.2.1 — 2024-01-06
- 7.2.0 — 2023-03-09

## README

# react-states

> Explicit states for predictable user experiences

## Install

```sh
npm install react-states
```

## Introduction to react-states

[![react-states](https://img.youtube.com/vi/4M--Kp41CjI/0.jpg)](https://www.youtube.com/watch?v=4M--Kp41CjI)

## Examples

- [Resizer in the Devtools](./src/devtools//Resizer.tsx)
- [ExcalidrawFirebase](https://github.com/codesandbox/excalidraw-firebase/tree/main/src)
- [FamilyScrum](https://github.com/christianalfoni/family-scrum-v2/tree/main/src)

## Documentation

- [API](./docs/api.md)
- [Patterns](./docs/patterns.md)

## Values

- "It is just a reducer"
- Simple utilities
- Enhanced type safety
- Reducer does not express side effects

## Learn by example

Instead of expressing your state implicitly:

```ts
type State = {
  isLoading: boolean;
  error: string | null;
  data: string[];
};
```

You can do so explicitly:

```ts
type State =
  | {
      state: 'NOT_LOADED';
    }
  | {
      state: 'LOADING';
    }
  | {
      state: 'LOADED';
      data: string[];
    }
  | {
      state: 'ERROR';
      error: string;
    };
```

With explicit states you can guard what actions are valid in what states using `transition`:

```ts
import { transition } from 'react-states';

const reducer = (prevState: State, action: Action) =>
  transition(prevState, action, {
    NOT_LOADED: {
      FETCH: () => ({
        state: 'LOADING',
      }),
    },
    LOADING: {
      FETCH_SUCCESS: (_, { data }) => ({
        state: 'LOADED',
        data,
      }),
      FETCH_ERROR: (_, { error }) => ({
        state: 'ERROR',
        error,
      }),
    },
    LOADED: {},
    ERROR: {},
  });
```

With additional utilities like `createStates`, `createActions` and `match` you will increase safety and reduce boilerplate in your code.

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