Skip to content

Jotai

@input-actions/jotai backs state with a single root atom inside a Jotai store. The shared-store option means other Jotai code in your app — vanilla atoms, atomWithStorage, jotai-devtools — runs on the same store, so subscriptions stay coherent across both surfaces.

Terminal window
pnpm add @input-actions/jotai jotai
import { createJotaiStoreSync } from '@input-actions/jotai';
export const store = createJotaiStoreSync({
user: { name: '' },
count: 0,
_async: {},
});

jotai is a static import, so creating the store is synchronous. It works at module scope and during SSR. createJotaiStore and ensureJotaiLoaded still exist for code that already awaits them, and they resolve immediately.

import { StoreProvider } from '@input-actions/core';
import { store } from './store';
<StoreProvider store={store}>
<App />
</StoreProvider>

The adapter accepts an options.store parameter — pass an existing Jotai store and the action-driven state lives alongside any other atoms in that store:

import { createStore } from 'jotai';
import { createJotaiStoreSync } from '@input-actions/jotai';
// One Jotai store powers everything below.
const jotaiStore = createStore();
export const inputActionsStore = createJotaiStoreSync(
{ user: { name: '' }, _async: {} },
{ store: jotaiStore },
);

Now:

  • Any vanilla atom you useAtom against jotaiStore reads/writes alongside the action-driven state.
  • atomWithStorage and other Jotai persistence atoms work as normal — the input-actions root atom can be persisted by wrapping it.
  • jotai-devtools sees the root atom in its panel.

The adapter doesn’t decompose your state into per-field atoms — the action protocol is path-based, and splitting paths into atoms would require a redesign of the action model. The single root atom is intentional. See JotaiAdapterOptions in packages/jotai/src/index.ts for the full type.

  • useAtom, useAtomValue, useSetAtom — work on any atoms you add to the shared store. They live alongside the input-actions state, not inside it.
  • atomWithStorage — wrap the input-actions state with localStorage / sessionStorage persistence. The atomic primitive that backs storage is independent of the action vocabulary; persistence “just works.”
  • jotai-devtools — the panel shows the root atom and any sibling atoms in the same store.
  • useAtomCallback, selectAtom — vanilla Jotai tooling works on the underlying atom.

The jotai example shows the shared-store pattern with atomWithStorage persistence layered on top.