Skip to content

Zustand

@input-actions/zustand backs state with a Zustand store. Useful when you want a small-footprint backend, when you’re sharing code with zustand-flavoured projects, or when you’d reach for zustand anyway and want the input-actions vocabulary on top.

Terminal window
pnpm add @input-actions/zustand zustand

Works with Zustand 4.3 or later and Zustand 5. The adapter uses Zustand’s vanilla store, so it doesn’t load Zustand’s React bindings.

import { createZustandStoreSync } from '@input-actions/zustand';
export const store = createZustandStoreSync({
user: { name: '' },
count: 0,
_async: {},
});

zustand is a static import, so creating the store is synchronous. It works at module scope and during SSR. createZustandStore and ensureZustandLoaded 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>

Unique benefit — minimal footprint, familiar shape

Section titled “Unique benefit — minimal footprint, familiar shape”

Zustand is ~1 kB and depends only on React. Picking this adapter:

  • Keeps the backend footprint tiny while still giving you the full input-actions vocabulary (async strategies, machines, bindings).
  • Looks familiar to teams already using zustand — the rest of the codebase can interop with the adapter’s underlying store if needed.

The adapter wraps Zustand’s create() once and exposes the standard Store<T> shape. Stable reference contract for useSyncExternalStore is preserved (the adapter caches its spread against the inner state — required to avoid an infinite render loop, see ADR 0014).

The Zustand subscribe API works at the adapter level — store.subscribe(listener) is the same shape Zustand consumers expect. For middleware (persist, devtools, immer), you’d typically apply them when calling create() directly. The adapter doesn’t expose the inner Zustand store via a public getter today; reach for the small ~80-line implementation in packages/zustand/src/index.ts if you want to layer middleware in.

For most apps, the minimal-store value (no boilerplate, no provider chain ceremony) is enough on its own.

Every async strategy and machine action flows through the executor exactly as with the other adapters. The adapter’s dispatch only handles sync action variants; async and machine actions are routed by the StoreProvider’s executor.

The global-state example demonstrates this adapter alongside Redux for direct comparison — same UI, same state, two backends.