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.
| Mode | Best for |
|---|---|
| No adapter | temporary state inside one mounted UI |
| localStorage | remembering choices on the same browser |
| URL search params | shareable links, SSR, and prefetching flows |
| Custom adapter | app-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
- Timeframe API: timeframe state and actions
- Preferences API: display preference state and actions
- Storage API: the adapter contract and custom adapter entry point
- Server-side rendering guide: URL state with server-rendered initial data