import { pageMetadata } from "@/lib/page-metadata"
export const metadata = pageMetadata("docs/api/jotai")
# @json-render/jotai
Jotai adapter for json-render's `StateStore` interface.
## Installation
```bash
npm install @json-render/jotai @json-render/core @json-render/react jotai
```
## jotaiStateStore
Create a `StateStore` backed by a Jotai atom.
```typescript
import { jotaiStateStore } from "@json-render/jotai";
```
### Options
| Option |
Type |
Required |
Description |
atom |
{'WritableAtom'} |
Yes |
A writable atom holding the state model. |
store |
Jotai Store |
No |
The Jotai store instance. Defaults to a new store created internally. Pass your own to share state with {''}. |
### Example
```typescript
import { atom } from "jotai";
import { jotaiStateStore } from "@json-render/jotai";
import { StateProvider } from "@json-render/react";
const uiAtom = atom>({ count: 0 });
const store = jotaiStateStore({ atom: uiAtom });
```
```tsx
{/* json-render reads/writes go through Jotai */}
```
### Shared Jotai Store
If your app already uses a Jotai `` with a custom store, pass it so both json-render and your components share the same state:
```typescript
import { atom, createStore } from "jotai";
import { Provider as JotaiProvider } from "jotai/react";
import { jotaiStateStore } from "@json-render/jotai";
import { StateProvider } from "@json-render/react";
const jStore = createStore();
const uiAtom = atom>({ count: 0 });
const store = jotaiStateStore({ atom: uiAtom, store: jStore });
```
```tsx
{/* Both json-render and useAtom() see the same state */}
```
## Re-exports
| Export |
Source |
StateStore |
@json-render/core |