fix bug: inconsistant naming for localstorage key for theme provider

This commit is contained in:
2026-03-12 20:50:49 +08:00
parent 1ca65e2670
commit 2ffd1efc61

View File

@@ -21,12 +21,16 @@ const ThemeProviderContext = createContext<ThemeProviderState>({
export function ThemeProvider({
children,
defaultTheme = "system",
storageKey = "vite-ui-theme",
storageKey = "theme",
...props
}: ThemeProviderProps) {
const [theme, setTheme] = useState<Theme>(
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme
)
const [theme, setTheme] = useState<Theme>(() => {
const stored = localStorage.getItem(storageKey)
if (stored === "dark" || stored === "light" || stored === "system") {
return stored
}
return defaultTheme
})
useEffect(() => {
const root = window.document.documentElement