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({ export function ThemeProvider({
children, children,
defaultTheme = "system", defaultTheme = "system",
storageKey = "vite-ui-theme", storageKey = "theme",
...props ...props
}: ThemeProviderProps) { }: ThemeProviderProps) {
const [theme, setTheme] = useState<Theme>( const [theme, setTheme] = useState<Theme>(() => {
() => (localStorage.getItem(storageKey) as Theme) || defaultTheme const stored = localStorage.getItem(storageKey)
) if (stored === "dark" || stored === "light" || stored === "system") {
return stored
}
return defaultTheme
})
useEffect(() => { useEffect(() => {
const root = window.document.documentElement const root = window.document.documentElement