Dev Helpers
← Back

Server theme preference

Place this file at app/preferences/page.tsx in an App Router project.

Open this example in the interactive library

Source code

// app/preferences/page.tsx

import { cookies } from "next/headers";

export default async function ServerThemePreference() {
  const jar = await cookies();
  const dark = jar.get("theme")?.value === "dark";
  return (
    <main
      style={{
        background: dark ? "#101010" : "white",
        color: dark ? "white" : "black",
        padding: "1rem",
      }}
    >
      <h1>Reading preferences</h1>
    </main>
  );
}