fix bug: inconsistant naming for localstorage key for theme provider
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user