nusm axolotlnusm
API Reference

createNusmStore

The complete store factory signature, options, persistence configuration, and return type.

function createNusmStore<TState>(
  initialState: TState,
  options?: CreateNusmStoreOptions<TState>,
): NusmStore<TState>

Creates a TanStack Store extended with nusm hydration and Devtools identity.

All options are optional. With no adapter, the store remains in memory, ready resolves immediately, and hydration.overall is not_configured. Applications can use this form alongside persisted nusm stores.

Options

Prop

Type

adapter

Enables persistence for this store through a built-in or custom NusmAdapter. A stable storeId or non-empty Devtools name is required when an adapter is present. Omit it for in-memory state.

persist

Chooses entire or slices. If omitted while an adapter is present, runtime behavior defaults to entire-store persistence; specify the strategy explicitly so intent is visible.

devtools

Enables the framework-neutral event bridge. Use an object to provide a display name and bounded eventLogCap.

onError

Receives adapter, hydration, persistence, external-event, and snapshot failures. Fatal hydration may also reject ready.

storeId

The stable logical identifier used to derive persistence keys and label Devtools state.

Hydration configuration

Prop

Type

merge applies to entire-store hydration. Slice values go through their individual apply functions.

Slice definition

Prop

Type

A slice must own only the selected value represented by its key.

Return value

Prop

Type

Use the inherited state, setState, and subscribe members for ordinary store work.

Lifecycle and Devtools types

type HydrationState =
  | "not_configured"
  | "pending"
  | "hydrated"
  | "discarded"
  | "error"

Prop

Type

Prop

Type

Prop

Type

Example

const store = createNusmStore(
  { locale: "en", sidebarOpen: true },
  {
    adapter: createLocalStorageAdapter(),
    devtools: { name: "UI preferences" },
    onError: console.error,
    persist: {
      strategy: "entire",
      hydrate: {
        validate: (value) => isPreferences(value),
      },
    },
    storeId: "ui-preferences",
  },
)

await store.ready

On this page