API ReferenceStorage
Storage Adapter
APIs exported from @octopus-energy/measurements/storage
StorageAdapter
The storage adapter accepted by useTimeframe, usePreferences, and the action
factories. Hooks derive state from getSnapshot during render with
useSyncExternalStore, and commits write back through set / remove.
import type { StorageAdapter } from "@octopus-energy/measurements/storage";StorageAdapterProp
Type
| Method | Purpose |
|---|---|
getSnapshot(key) | Returns the current raw snapshot for a hook storage key. |
readSnapshot(snapshot, parse) | Converts a snapshot into parsed hook state. Use parse(snapshot) when the snapshot is already the stored value. |
subscribe(key, listener) | Notifies React when the snapshot for a key may have changed. |
set(key, value) | Writes serialized hook state. |
remove(key) | Removes serialized hook state. |
When storage is omitted, hooks keep local React state only. That state resets
when the hook unmounts.
createStorageAdapter
Creates a complete StorageAdapter. readSnapshot is optional in the input;
when omitted, it defaults to parse(snapshot).
import { createStorageAdapter } from "@octopus-energy/measurements/storage";createStorageAdapterProp
Type
CreateStorageAdapterInputProp
Type
Related
- Local Storage: browser localStorage adapter (shared across tabs)
- Session Storage: browser sessionStorage adapter (per-tab isolation)
- nuqs Client: client URL search param adapter
- nuqs Server: server search param parsers