Lynx

useSeedClassName

A hook that returns the theme className to apply to root `<page>` and subscribes to theme changes.

Available since@seed-design/lynx-react@0.3.0

Import

import { useSeedClassName } from "@seed-design/lynx-react";

useSeedClassName is included in the @seed-design/lynx-react package. It's a reactive version of getSeedClassName(), subscribing to lynx.__globalProps.theme changes via useGlobalProps() and returning the updated className when the theme changes.

Usage

Basic Usage

Apply to the root <page> element.

import { root } from "@lynx-js/react";
import { useSeedClassName } from "@seed-design/lynx-react";

function Root() {
  const seedClassName = useSeedClassName({ colorMode: "system" });
  return (
    <page className={seedClassName}>
      <App />
    </page>
  );
}

root.render(<Root />);

colorMode Option

colorMode settingDevice settingTheme class returned
system (default)Light modeseed-user-color-scheme-light
systemDark modeseed-user-color-scheme-dark
light-only(irrelevant)seed-user-color-scheme-light
dark-only(irrelevant)seed-user-color-scheme-dark

When system, it reads the lynx.__globalProps.theme value and follows the device's dark mode setting.

How It Works

useSeedClassName() internally subscribes to lynx.__globalProps via useGlobalProps(). When the host changes the theme, components using this hook re-render and return the className that matches the updated theme.

The className mapping logic is identical to the pure function getSeedClassName(). The only difference is whether it subscribes to theme changes.

  • useSeedClassName(): A hook that subscribes to theme changes. Use it wherever you need to react to theme changes, such as the root <page>.
  • getSeedClassName(): A pure function that reads the theme only once, at call time. Use it in static contexts that don't need to react to theme changes.

On the web (React), a bundler plugin handles the theme automatically, but on Lynx, you subscribe explicitly with useSeedClassName(). See the Theming docs for the theme system overall.

API

Parameters

PropertyTypeDefaultDescription
colorMode"system" | "light-only" | "dark-only""system"How the theme is determined. system follows the device setting; light-only / dark-only pin the theme.

Return

TypeDescription
stringThe theme class to apply (seed-user-color-scheme-light or seed-user-color-scheme-dark).

Usage Notes

  • Requires @lynx-js/react 0.117.0 or higher, since it depends on useGlobalProps().
  • Being a hook, it can only be called from a component body. If you don't need to react to theme changes, use the pure function getSeedClassName() instead.

Table of contents