useSeedClassName
A hook that returns the theme className to apply to root `<page>` and subscribes to theme changes.
Import
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.
colorMode Option
colorMode setting | Device setting | Theme class returned |
|---|---|---|
system (default) | Light mode | seed-user-color-scheme-light |
system | Dark mode | seed-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
| Property | Type | Default | Description |
|---|---|---|---|
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
| Type | Description |
|---|---|
string | The theme class to apply (seed-user-color-scheme-light or seed-user-color-scheme-dark). |
Usage Notes
- Requires
@lynx-js/react0.117.0or higher, since it depends onuseGlobalProps(). - 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.