useTheme
This hook is used to get and set the theme, and store the themeMode into localStorage.
Overview
This hook is used to get and set the theme, and store the themeMode into localStorage.
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTheme.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTheme.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTheme.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useTheme.jsonThis hook is used to get and set the theme, and store the themeMode into localStorage.
Examples
Default usage
API
const { theme, themeMode, setThemeMode } = useTheme({
localStorageKey?: string;
});Params
| Property | Description | Type | Default |
| -- | -- | | ---- |
| theme | current display theme | "light" \| "dark" | if themeMode is "system" then equals to system setting,otherwise equals to themeMode |
| themeMode | selected theme mode | "light" \| "dark" \| "system" | equals to localStorage "themeMode", otherwise equals to "system" |
| setThemeMode | select theme mode | (mode: "light" \| "dark" \| "system") => void | |