Skip to content
brix.v2.15.0+b120c49

Search documentation

Loading search…

    Documentation menu
    Docs / Pages and UIRead Markdown
    On this page

    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 createStorageKey from brix/storage.
    • Values are stored as JSON. Writes validate and persist the schema's input; reads return the schema's parsed output, or null when the item is missing, malformed, or invalid.
    • Local and session APIs return null on 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.

    Read and write outside components

    #

    Use typed local, session, and generic storage helpers; handle validation, unavailable storage, and tests.