Skip to main content
React bindings live in @brushy/storage-react (not in @brushy/storage). Hooks use useSyncExternalStore, not useEffect, for persisted values.

Install

StorageProvider

Wraps your React tree with a shared Storage instance.

Props

Storage
Existing instance. Preferred for DI-registered singletons.
StorageOptions
Creates a new instance when storage is omitted: createStorage(options).
ReactNode
required
App tree.
When neither storage nor options is passed, a default in-memory instance (id: "@brushy:default") is used.

useStorage(key, initialValue, options?)

Return shape

Unlike v1 @brushy/localstorage tuple hooks, v2 returns an object:

Per-hook TTL

Functional updates

useStorageContext

Access the underlying Storage instance for imperative operations outside hooks:

getDefaultStorage

Non-hook access to the provider’s fallback instance:

SSR behavior

useStorage passes getServerSnapshot returning initialValue, so server HTML matches the first client render before hydration reads persisted data.
See Node vs browser.

DI integration

Register storage once in your DI container and pass the resolved instance to the provider:
Example layout in the Vite project: examples/vite/src/providers/storage-bridge.tsx.