Skip to main content

Function: defineStore()

function defineStore<S>(name, options?): StoreHooks<S>;

Bind a store name — and optionally persistence — once, at module level.

Like defineChannel, this does not construct anything: it registers the options the registry will use when the store is first needed, so importing the module has no side effect. The store stays a singleton per name, so defineStore('settings', { persist }) and a bare useSharedState('theme', 'dark', { store: 'settings' }) elsewhere resolve to the same store, and both get persistence.

Must run before that store exists. Module evaluation always precedes render, so intended usage is automatic; if it does run late it throws rather than quietly handing back a store with no persistence.

Type Parameters

Type ParameterDefault type
S extends Record<string, unknown>Record<string, unknown>

Parameters

ParameterType
namestring
optionsDefineStoreOptions

Returns

StoreHooks<S>