Meet Frontfriend.Your brand. Your rules. Your agents, connected.Explore what’s new
DocumentationTheme Provider

Theme Provider

Interactive preview

Rendered from the shared Frontfriend stories with React Base, the same preview Studio shows. Styling comes from your Design System; the code below is native to Base UI.

Installation

Complete project setup first. Your configuration must select react/base and include your Design System ID.

pnpm exec frontfriend download theme-provider -f react --primitive base

Review dependencies reported by the downloader and keep your source changes in version control.

Usage

import { ThemeProvider, useTheme } from "@/components/ui/theme-provider";
import { Button } from "@/components/ui/button";
import * as React from "react";
function ThemeStatus() {
  const { theme } = useTheme();
  return (
    <div className="space-y-4 rounded-lg border p-6">
      <p role="status">Provider theme: {theme}</p>
      <Button>Theme example</Button>
    </div>
  );
}
function ThemePlayground({
  defaultTheme = "system",
}: {
  defaultTheme?: "light" | "dark" | "system";
}) {
  const [storageKey] = React.useState(
    () => `theme-example-${crypto.randomUUID()}`,
  );
  return (
    <ThemeProvider
      key={defaultTheme}
      defaultTheme={defaultTheme}
      storageKey={storageKey}
    >
      <ThemeStatus />
    </ThemeProvider>
  );
}
<ThemePlayground defaultTheme="system" />;

API reference

Frontfriend-owned props. Native HTML and inherited primitive props remain documented by Base UI.

Prop Type Default Description
defaultTheme Theme "system" Initial provider theme. Changing it remounts this example without saving a preference.
storageKey string "vite-ui-theme"

Configuration determines the actual classes and available styling hooks. See Theming & component configuration before introducing a repeated local override.