Skip to Content
Octopus Energy Packages
Concepts

State and storage

How timeframe and preference state can be owned or persisted

Measurement charts usually have two kinds of interactive state. Timeframe state controls what data is shown. Preference state controls how that data is shown. The package lets you use that state ephemerally or persist it through a storage adapter.

Timeframe state

Timeframe state answers questions like:

  • which date is selected?
  • is the user viewing a day, week, month, or year?
  • what exact request bounds does that selection resolve to?

Because timeframe affects request bounds, changing it usually causes a refetch.

Preference state

Preference state answers display questions like:

  • should values be shown as kWh or cost?
  • should standing charges be included?
  • should the chart or table view be shown?

Preferences usually affect transforms and display, not the measurement request itself.

Storage adapters

By default, hooks can own their own React state. When state should survive a reload or appear in the URL, pass a storage adapter.

ModeBest for
No adaptertemporary state inside one mounted UI
localStorageremembering choices on the same browser
URL search paramsshareable links, SSR, and prefetching flows
Custom adapterapp-specific persistence requirements

Adapters are optional. They are a persistence detail, not a requirement for using timeframe or preferences.

Scoped state

Some pages render multiple measurement cards at once, for example separate electricity and gas cards. Scopes let each card keep independent timeframe and preference state while using the same underlying storage mechanism.

Where to go next

On this page