stable

zustand

Zustand adapter — createNoydbStore() mirrors defineNoydbStore for Zustand, auto-hydrating and auto-refreshing a state slice from a noy-db Collection.

@noy-db/in-zustand · pnpm add @noy-db/hub @noy-db/in-zustand zustand Zustand adapter for noy-db.

What it does

createNoydbStore(getCollection) produces a Zustand StateCreator<NoydbZustandSlice<T>> backed by a Collection<T>. The slice exposes records (keyed by id), loading, error, and put / remove / refresh methods; reads hydrate on first access and auto-refresh on every change event from the collection, while writes go through the collection so they're encrypted and replicated by the sync engine. getCollection is called lazily, so the store can be wired while the Noydb instance is still opening asynchronously — the first refresh() waits for it to resolve.

Usage

import { create } from 'zustand'
import { createNoydbStore } from '@noy-db/in-zustand'

const useInvoices = create(
  createNoydbStore(() => db.vault('acme').collection<Invoice>('invoices')),
)

See also

  • in-* family
  • react — Zustand is commonly paired with React
  • pinia — the equivalent store-factory pattern for Vue/Pinia