Skip to Content
Octopus Energy Packages

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";
StorageAdapter

Prop

Type

MethodPurpose
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";
createStorageAdapter

Prop

Type

CreateStorageAdapterInput

Prop

Type


On this page