Dev Helpers

Next.js / Request cookie pages

Preferred unit label

Dev Helpers · September 14, 2026

Unit preferences might arrive from a cookie, query or default setting. Validate the chosen value before incorporating it into a label.

Worked example

// app/preferences/page.tsx

import { cookies } from "next/headers";

export default async function PreferredUnitLabel() {
  const jar = await cookies();
  const metric = jar.get("units")?.value !== "imperial";
  return <p>Desk width: {metric ? "120 cm" : "47.2 in"}</p>;
}

Implementation notes

Caching and personalization must agree. A response that varies by a user's unit preference must not present another reader's chosen label.

Try it yourself

Supply an unsupported unit and inspect the fallback.

Open the Next.js example →

Editorial date September 14, 2026 · Published December 6, 2026

Related articles

Free bin volume

Free storage volume depends on consistent dimensions and units. Derive capacity and usage in the same unit before formatting a human-readable summary.

Draft preview indexing

Draft pages need deliberate indexing metadata. An indexing directive controls crawler intent, while access to unpublished material needs a separate permission check.

Party size allocation

Allocating a party into groups is an integer problem. The remainder determines whether another group is needed and how full it will be.