Changelog - 2026-11-08
useStoredState can turn its storage off with a null key
New FeatureIn one line. A hook call cannot be conditional, so useStoredState now takes key: string | null. With null it stores nothing and keeps its value in memory, like useState.
tsx
import { useStoredState } from '@venizia/ardor';
export function Sidebar({ userId }: { userId: string | undefined }) {
// Nothing is stored until the user is known.
const { value, setValue } = useStoredState({
key: userId ? `@app/prefs/${userId}/sidebar` : null,
defaultValue: 'open',
});
return <button onClick={() => setValue(value === 'open' ? 'closed' : 'open')}>{value}</button>;
}What changed
- Allow
keyto benullto disable storage. Whennull, the hook acts like standard ReactuseStateby keeping state in memory, setting the initial value todefaultValue, and skipping all storage reads, writes and listeners.remove()puts the value back todefaultValueand touches no storage. - Moving from
nullto a storage key. Switchingkeyto a string starts reading that key and discards any temporary value held in memory. - Moving from a storage key to
null. Switchingkeytonullresets the value todefaultValueand leaves the stored value untouched. A delayed write (writeDelayMs) that is still pending is written to the previous key.
Who is affected
- A component that stores state only when something is known (a user id, a feature flag). Pass
nullas the key until it is. - All other apps. No action needed; a string key works as before.
See Hooks.