Skip to content

hooks/keyed-store

import { … } from 'zidane-ui'ui/src/hooks/keyed-store.ts

Functions#

createKeyedStoreFunction#

A new empty KeyedStore.

TypeScript
function createKeyedStore<V>(): KeyedStore<V>
Type parameters
NameDescription
V

ui/src/hooks/keyed-store.ts:22

useKeyedValueFunction#

The value under key (null when unset or no key), re-rendering only when that key changes.

TypeScript
function useKeyedValue<V>(
  store: KeyedStore<V>,
  key: string | null | undefined,
): V | null
Type parameters
NameDescription
V
Parameters
NameTypeDescription
storeKeyedStore<V>

The store to read.

keystring | null | undefined

The key; null / undefined reads nothing.

V | null

ui/src/hooks/keyed-store.ts:58

Interfaces#

KeyedStoreInterface#

Values by key, each key with its own subscribers.

TypeScript
interface KeyedStore<V>
KeyedStore type parameters
NameDescription
V
KeyedStore properties
NameTypeDescription
delete(key: string) => void

Forget key (a deleted session): its readers see no value.

get(key: string) => V | undefined

The value under key, if any.

set(key: string, value: V) => void

Store value under key and notify that key's subscribers (nothing when it is the same value).

subscribe(key: string, listener: () => void) => () => void

Call listener whenever key changes; returns the unsubscribe.

ui/src/hooks/keyed-store.ts:10