Browser storage
brix/storage provides schema-validated persisted browser state. Use reactive bindings in components and raw helpers in non-component code.
Choose localStorage for preferences that should survive browser restarts and synchronize across
same-origin tabs. Choose sessionStorage for tab-scoped state that should survive a reload but not
outlive the tab. Neither is a database or a safe place for credentials: users can read and change
both. Use stores when state only needs to live in memory on the current page.
The same contract applies everywhere:
- Every key has a Zod schema, defined once with
createStorageKeyfrombrix/storage. - Values are stored as JSON. Writes validate and persist the schema's input; reads return the
schema's parsed output, or
nullwhen the item is missing, malformed, or invalid. - Local and session APIs return
nullon the server, so the first render never depends on saved data. - Preact components use hooks from
brix/hooks; managed React applications use the same hooks from@brix/react.
Bind storage to UI
#Define reusable keys and use Preact or React hooks with SSR-safe reactive synchronization.