Skip to Content
Octopus Energy Packages

Session Storage

APIs exported from @octopus-energy/measurements/storage/session-storage

Use this entry point for browser sessionStorage persistence.

import { createSessionStorageAdapter } from "@octopus-energy/measurements/storage/session-storage";

createSessionStorageAdapter

Creates a StorageAdapter backed by window.sessionStorage.

Data persists for the lifetime of the browser tab and is automatically discarded when the tab is closed. Each tab has its own isolated storage; changes in one tab are not visible in other tabs.

The adapter is safe for SSR: server snapshots return null and browser-only operations no-op when window.sessionStorage is unavailable.

import { createSessionStorageAdapter } from "@octopus-energy/measurements/storage/session-storage";
createSessionStorageAdapter

Prop

Type

import { createSessionStorageAdapter } from "@octopus-energy/measurements/storage/session-storage";
import { useTimeframe } from "@octopus-energy/measurements/timeframe";

const storage = createSessionStorageAdapter({ scope: "electricity" });
const [timeframe, timeframeActions] = useTimeframe({ storage, timezone });
CreateSessionStorageAdapterOptions

Prop

Type

Scoping

When scope is provided, all keys are suffixed with :{scope} to prevent collisions between multiple instances on the same page.

const elec = createSessionStorageAdapter({ scope: "electricity" });
// "measurements:timeframe" → "measurements:timeframe:electricity"

const gas = createSessionStorageAdapter({ scope: "gas" });
// "measurements:timeframe" → "measurements:timeframe:gas"

On this page