Skip to Content
Octopus Energy Packages

Quick Start

Build a minimal EnergyOverview with measurements and Coral

This Quick Start builds a minimal electricity EnergyOverview using @octopus-energy/measurements, TanStack Query, and Coral components.

Use the full EnergyOverview tutorial when you need a multi-supply-point implementation with clearer production boundaries.

Create storage

Use local storage when a client-rendered overview should remember timeframe and preference choices across reloads.

EnergyOverview.tsx
import { createLocalStorageAdapter } from "@octopus-energy/measurements/storage/local-storage";

const storage = createLocalStorageAdapter();

Create timeframe and preferences

EnergyOverview.tsx
import { usePreferences } from "@octopus-energy/measurements/preferences";
import { useTimeframe } from "@octopus-energy/measurements/timeframe";

const [timeframe, timeframeActions] = useTimeframe({
  storage,
  timezone: "Europe/London",
});

const [preferences, preferencesActions] = usePreferences({ storage });

Fetch supply points and measurements

Resolve market supply points first, then use them with the selected timeframe to fetch measurements.

EnergyOverview.tsx
import { groupMeasurements } from "@octopus-energy/measurements";
import { createMeasurementsOverview } from "@octopus-energy/measurements/overview";
import {
  marketSupplyPointsQueryOptions,
  measurementsQueryOptions,
} from "@octopus-energy/measurements/react-query";
import { useQuery } from "@tanstack/react-query";

const client = useGraphQLClient();

const { data: marketSupplyPoints } = useQuery(
  marketSupplyPointsQueryOptions(client, {
    accountNumber,
    propertyId,
    utilityMarkets,
  }),
);

const measurements = useQuery(
  measurementsQueryOptions(client, {
    propertyId,
    timeframe,
    marketSupplyPoints,
  }),
);

const { electricity } = groupMeasurements(measurements.data, {
  by: ["utility"],
});

const overview = createMeasurementsOverview(electricity?.measurements, {
  preferences,
  timeframe,
});

Map to Coral props

Use the compat helpers to adapt measurements primitives to Coral component props.

EnergyOverview.tsx
import {
  getCardProps,
  getDateRangeDisplay,
  getTimeframeProps,
} from "@octopus-energy/measurements/compat";
import { enGB } from "date-fns/locale/en-GB";

const { navigation, timeframeControls, toggleButton } = getTimeframeProps({
  timeframe,
  timeframeActions,
});

const card = getCardProps({
  overview,
  preferences,
  preferencesActions,
  utility: "electricity",
});

const dateRangeDisplay = getDateRangeDisplay(timeframe, enGB);

Render the overview

Render Coral's EnergyOverview controls and card using the mapped props. Your app owns the exact layout, labels, icons, and authenticated GraphQL client.

EnergyOverview.tsx
<EnergyOverview dateLocale={enGB} loading={measurements.isPending}>
  <EnergyOverviewTimeframeControls {...timeframeControls}>
    <EnergyOverviewTimeframeToggleButton {...toggleButton}>
      {/* Render interval options */}
    </EnergyOverviewTimeframeToggleButton>
    <EnergyOverviewTimeframeNavigation {...navigation} />
  </EnergyOverviewTimeframeControls>

  <EnergyOverviewCard
    {...card}
    currency="GBP"
    dateLocale={enGB}
    locale="en-GB"
    timezone={timeframe.timezone}
  >
    <EnergyOverviewHeader>
      <EnergyOverviewTitle>Electricity</EnergyOverviewTitle>
      <EnergyOverviewViewType />
    </EnergyOverviewHeader>

    <EnergyOverviewDataSection>
      <EnergyOverviewTimeframeSummary>
        <EnergyOverviewDateDisplay>{dateRangeDisplay}</EnergyOverviewDateDisplay>
        <EnergyOverviewTotalValue />
      </EnergyOverviewTimeframeSummary>

      <EnergyOverviewSettingsAndDisplay>
        <EnergyOverviewSettingsControls>
          <EnergyOverviewStandingCharge />
          <EnergyOverviewUnitToggle>{/* Render kWh / £ options */}</EnergyOverviewUnitToggle>
        </EnergyOverviewSettingsControls>
        <EnergyOverviewEnergyUsage>Electricity usage</EnergyOverviewEnergyUsage>
      </EnergyOverviewSettingsAndDisplay>
    </EnergyOverviewDataSection>
  </EnergyOverviewCard>
</EnergyOverview>

Next

  • Tutorial: build a more complete multi-supply-point overview in focused steps.
  • Next steps: add data-backed defaults, URL persistence, and server rendering.

On this page