import { pageMetadata } from "@/lib/page-metadata"
export const metadata = pageMetadata("docs/api/zustand")
# @json-render/zustand
Zustand adapter for json-render's `StateStore` interface.
Requires Zustand v5+. Zustand v4 is not supported due to breaking API changes in the vanilla store interface.
## Installation
```bash
npm install @json-render/zustand @json-render/core @json-render/react zustand
```
## zustandStateStore
Create a `StateStore` backed by a Zustand vanilla store.
```typescript
import { zustandStateStore } from "@json-render/zustand";
```
### Options
| Option |
Type |
Required |
Description |
store |
{'StoreApi'} |
Yes |
A Zustand vanilla store (from createStore in zustand/vanilla). |
selector |
{'(state: S) => StateModel'} |
No |
Select the json-render slice from the store state. Defaults to the entire state. |
updater |
{'(nextState: StateModel, store: StoreApi) => void'} |
No |
Apply a state change back to the store. Defaults to a shallow merge. |
### Example
```typescript
import { createStore } from "zustand/vanilla";
import { zustandStateStore } from "@json-render/zustand";
import { StateProvider } from "@json-render/react";
const bearStore = createStore(() => ({
count: 0,
name: "Bear",
}));
const store = zustandStateStore({ store: bearStore });
```
```tsx
{/* json-render reads/writes go through Zustand */}
```
### Nested Slice
```typescript
const appStore = createStore(() => ({
ui: { count: 0 },
auth: { token: null },
}));
const store = zustandStateStore({
store: appStore,
selector: (s) => s.ui,
updater: (next, s) => s.setState({ ui: next }),
});
```
## Re-exports
| Export |
Source |
StateStore |
@json-render/core |