David Khourshid 6bcaaad57d feat: Add `@xstate/store` (atom) support (#157) 4 月之前
..
src 6bcaaad57d feat: Add `@xstate/store` (atom) support (#157) 4 月之前
README.md 6bcaaad57d feat: Add `@xstate/store` (atom) support (#157) 4 月之前
package.json 6bcaaad57d feat: Add `@xstate/store` (atom) support (#157) 4 月之前
tsconfig.json 6bcaaad57d feat: Add `@xstate/store` (atom) support (#157) 4 月之前
tsup.config.ts 6bcaaad57d feat: Add `@xstate/store` (atom) support (#157) 4 月之前

README.md

@json-render/xstate-store

XState Store adapter for json-render's StateStore interface. Wire an @xstate/store atom as the state backend for json-render.

Installation

npm install @json-render/xstate-store @json-render/core @json-render/react @xstate/store

[!NOTE] This adapter requires @xstate/store v3+.

Usage

import { createAtom } from "@xstate/store";
import { xstateStoreStateStore } from "@json-render/xstate-store";
import { StateProvider } from "@json-render/react";

// 1. Create an atom
const uiAtom = createAtom({ count: 0 });

// 2. Create the json-render StateStore adapter
const store = xstateStoreStateStore({ atom: uiAtom });

// 3. Use it
<StateProvider store={store}>
  {/* json-render reads/writes go through @xstate/store */}
</StateProvider>

API

xstateStoreStateStore(options)

Creates a StateStore backed by an @xstate/store atom.

Options

Option Type Required Description
atom Atom<StateModel> Yes An @xstate/store atom (from createAtom) holding the json-render state model