# @reckona/mreact-store

> Global and shared reactive state primitives for mreact.

Latest version **0.0.225** (published 2026-09-15) · MIT license · 976 weekly downloads

## Install

```sh
npm install @reckona/mreact-store
pnpm add @reckona/mreact-store
yarn add @reckona/mreact-store
bun add @reckona/mreact-store
```

## Health

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

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; pre 1.0.

Negative: declining downloads.

## Facts

| | |
|---|---|
| Version | 0.0.225 |
| Published | 2026-09-15 |
| First published | 2026-05-16 |
| Weekly downloads | 976 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 111.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Maintainers | tatsuokaniwa |
| Keywords | jsx, mreact, reactive, state, store, typescript |

## Links

- npm: https://www.npmjs.com/package/@reckona/mreact-store
- Repository: https://github.com/t-k/mreact
- Homepage: https://github.com/t-k/mreact/tree/main/packages/store#readme
- Issues: https://github.com/t-k/mreact/issues
- npm.io page: https://npm.io/package/@reckona/mreact-store

## Dependencies (2)

- [@reckona/mreact-devtools](https://npm.io/package/@reckona/mreact-devtools.md) 0.0.225
- [@reckona/mreact-reactive-core](https://npm.io/package/@reckona/mreact-reactive-core.md) 0.0.225

## Alternatives

- [regular-state](https://npm.io/package/regular-state.md) — 410 weekly downloads
- [@pacote/flux-actions](https://npm.io/package/@pacote/flux-actions.md) — 65 weekly downloads
- [@pilotlab/lux-debug](https://npm.io/package/@pilotlab/lux-debug.md) — 39 weekly downloads
- [vue-persist-state](https://npm.io/package/vue-persist-state.md) — 19 weekly downloads
- [xmodel-svelte](https://npm.io/package/xmodel-svelte.md) — 4 weekly downloads

## Recent versions

- 0.0.225 (latest) — 2026-09-15
- 0.0.224 — 2026-09-15
- 0.0.223 — 2026-09-13
- 0.0.222 — 2026-09-13
- 0.0.221 — 2026-09-12
- 0.0.220 — 2026-09-12
- 0.0.219 — 2026-09-12
- 0.0.218 — 2026-09-12
- 0.0.217 — 2026-09-12
- 0.0.216 — 2026-09-10
- 0.0.215 — 2026-09-09
- 0.0.214 — 2026-09-09
- 0.0.213 — 2026-09-07
- 0.0.212 — 2026-09-06
- 0.0.211 — 2026-09-06
- … 209 more at https://npm.io/package/@reckona/mreact-store/versions

## README

# @reckona/mreact-store

`@reckona/mreact-store` provides global and shared state primitives for mreact.
It builds on `cell` from `@reckona/mreact-reactive-core` and keeps selectors,
actions, transactions, and persistence as small composable pieces.

## Basic Usage

```ts
import { createStore, shallowEqual } from "@reckona/mreact-store";

const counter = createStore({ count: 0, label: "counter" });

const count = counter.select((state) => state.count);
const snapshot = counter.select((state) => ({ label: state.label }), shallowEqual);

counter.set((state) => ({ count: state.count + 1 }));
```

Use `store.view` for reference-stable deep readonly reads and `store.snapshot()` when an independent mutable copy is required. Readonly views do not freeze the live object, so updates still go through `set()`, `replace()`, or `update()`.

```ts
const readonlyState = counter.view.get();
const independent = counter.snapshot();
independent.count = 10;
```

## Core APIs

- `createStore()` creates a store with state and actions.
- `store.select()` subscribes to a reactive slice of store state and returns a selected cell with `dispose()` for code that creates selectors outside the framework cleanup lifecycle.
- `store.subscribe()` observes changes from outside the framework runtime.
- `store.view` exposes readonly state, selectors, and subscriptions without cloning each read.
- `store.snapshot()` clones arrays, plain objects, dates, regular expressions, URLs, maps, sets, ArrayBuffers, DataViews, and typed arrays. Functions remain shared references; arbitrary class instances, weak collections, and promises are rejected.
- `store.transaction()` batches multiple updates into one notification.
- `createRequestStoreFactory()` creates request-isolated store instances.
- The `persist` option connects store state to a storage adapter. Pass a callback for write-only persistence, or use `{ load, save, version, migrate }` when the store should hydrate and migrate saved state. Persisted envelopes are version-tagged so ordinary application values shaped like `{ state, version }` remain ordinary state. To read a legacy untagged `{ state, version }` record during migration, set the literal `acceptLegacyPersistedState: true`; this opt-in prevents domain state from being guessed as an envelope. When the choice comes from a runtime boolean, branch into separate current and legacy option objects so TypeScript can preserve the corresponding load contract.
- `store.persistence.ready` resolves after initial hydration, while `store.persistence.status` and `store.persistence.error` expose load, migrate, or later save failures without producing unhandled promise rejections. A local update made during hydration wins by default; choose `hydrationConflict: "replace"`, `"merge"`, or a resolver when persisted data should take precedence or be combined deliberately.
- Historical persistence can use a distinct schema type: `createStore<CurrentState, PersistedState>()` types `migrate()` with the saved shape, while `validate()` checks the loaded value and `validateCurrent()` checks the migrated current shape. A configured version mismatch without a migrator keeps the initial state and reports a load error.
- `store.transaction()` is synchronous. The type and runtime contract reject promises and thenables, roll back synchronous writes detected before notification, and require awaited work to finish before starting a later transaction.

## Positioning

Use `@reckona/mreact-query` for server state, `@reckona/mreact-forms` for form
state, and `@reckona/mreact-store` for application-wide UI or domain state.

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