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 Parameter | Description |
|---|---|
K extends string | The literal storage key name |
T | The decoded value type for the key |
Parameters
| Parameter | Type | Description |
|---|---|---|
key | K | The unprefixed storage key |
options | UseMnemonicKeyOptions<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<TSchemaextendsKeySchema<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 Parameter | Description |
|---|---|
K extends string | The literal storage key name |
TSchema extends KeySchema<unknown, K, JsonSchema> | - |
Parameters
| Parameter | Type | Description |
|---|---|---|
keySchema | TSchema | - |
options | SchemaBoundKeyOptions<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);