Update dependencies
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { Theme, ThemeProviderProps, ThemeProviderState } from "$/types/ThemeTypes";
|
||||
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
||||
import { createContext, use, useEffect, useMemo, useState } from "react";
|
||||
|
||||
|
||||
const themeInitialState: ThemeProviderState = {
|
||||
@@ -17,7 +17,7 @@ export default function ThemeProvider(props: Readonly<ThemeProviderProps>){
|
||||
storageKey = "mattrixwv-ui-theme"
|
||||
} = props;
|
||||
|
||||
const [ theme, setTheme ] = useState<Theme>((localStorage.getItem(storageKey) as Theme) || defaultTheme);
|
||||
const [ theme, setTheme ] = useState<Theme>(() => (localStorage.getItem(storageKey) as Theme) || defaultTheme);
|
||||
|
||||
useEffect(() => {
|
||||
const root = globalThis.document.documentElement;
|
||||
@@ -43,16 +43,16 @@ export default function ThemeProvider(props: Readonly<ThemeProviderProps>){
|
||||
}), [storageKey, theme]);
|
||||
|
||||
return (
|
||||
<ThemeProviderContext.Provider value={value}>
|
||||
<ThemeProviderContext value={value}>
|
||||
{children}
|
||||
</ThemeProviderContext.Provider>
|
||||
</ThemeProviderContext>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// eslint-disable-next-line react-refresh/only-export-components
|
||||
export function useTheme(){
|
||||
const context = useContext(ThemeProviderContext);
|
||||
const context = use(ThemeProviderContext);
|
||||
|
||||
if(!context){
|
||||
throw new Error("useTheme must be used within a ThemeProvider");
|
||||
|
||||
Reference in New Issue
Block a user