Skip to main content
Version: 1.2.1-beta1.0

Function: defineMnemonicKey()

Call Signature

defineMnemonicKey<K, T>(key, options): MnemonicKeyDescriptor<T, K>

Defined in: src/Mnemonic/key.ts:31

Define a reusable, importable contract for a persisted key.

This packages the storage key and the canonical useMnemonicKey(...) options into a single object that can be shared across components, docs, and generated code.

Type Parameters

Type ParameterDescription
K extends stringThe literal storage key name
TThe decoded value type for the key

Parameters

ParameterTypeDescription
keyKThe unprefixed storage key
optionsUseMnemonicKeyOptions<T>Canonical hook options for the key

Returns

MnemonicKeyDescriptor<T, K>

A descriptor that can be passed directly to useMnemonicKey(...)

Example

const themeKey = defineMnemonicKey("theme", {
defaultValue: "light" as "light" | "dark",
listenCrossTab: true,
});

const { value, set } = useMnemonicKey(themeKey);

Call Signature

defineMnemonicKey<K, TSchema>(keySchema, options): MnemonicKeyDescriptor<TSchema extends KeySchema<TValue, string, JsonSchema> ? TValue : never, TSchema["key"]>

Defined in: src/Mnemonic/key.ts:35

Define a reusable, importable contract for a persisted key.

This packages the storage key and the canonical useMnemonicKey(...) options into a single object that can be shared across components, docs, and generated code.

Type Parameters

Type ParameterDescription
K extends stringThe literal storage key name
TSchema extends KeySchema<unknown, K, JsonSchema>-

Parameters

ParameterTypeDescription
keySchemaTSchema-
optionsSchemaBoundKeyOptions<TSchema extends KeySchema<infer TValue, string, JsonSchema> ? TValue : never>Canonical hook options for the key

Returns

MnemonicKeyDescriptor<TSchema extends KeySchema<TValue, string, JsonSchema> ? TValue : never, TSchema["key"]>

A descriptor that can be passed directly to useMnemonicKey(...)

Example

const themeKey = defineMnemonicKey("theme", {
defaultValue: "light" as "light" | "dark",
listenCrossTab: true,
});

const { value, set } = useMnemonicKey(themeKey);