refactor: add inited state

This commit is contained in:
Derrick Hammer 2023-10-12 13:18:17 -04:00
parent 971991e808
commit cbfce62f95
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 12 additions and 1 deletions

View File

@ -34,6 +34,8 @@ export type LumeContextType = {
isLoggedIn: boolean; isLoggedIn: boolean;
setIsLoggedIn: (value: boolean) => void; setIsLoggedIn: (value: boolean) => void;
lume: LumeObject; lume: LumeObject;
inited: boolean;
setInited: React.Dispatch<React.SetStateAction<boolean>>;
ready: boolean; ready: boolean;
setReady: React.Dispatch<React.SetStateAction<boolean>>; setReady: React.Dispatch<React.SetStateAction<boolean>>;
}; };
@ -45,6 +47,7 @@ const LumeContext = createContext<LumeContextType | undefined>(undefined);
const LumeProvider = ({ children }) => { const LumeProvider = ({ children }) => {
const [isLoggedIn, setIsLoggedIn] = useState(false); const [isLoggedIn, setIsLoggedIn] = useState(false);
const [ready, setReady] = useState<boolean>(false); const [ready, setReady] = useState<boolean>(false);
const [inited, setInited] = useState<boolean>(false);
const [lume, setLume] = useState<LumeObject>({ networks: [] }); const [lume, setLume] = useState<LumeObject>({ networks: [] });
const statusUnsubs = useRef(new Map()); const statusUnsubs = useRef(new Map());
const isMounted = useRef(true); // Use a ref to track mounting const isMounted = useRef(true); // Use a ref to track mounting
@ -137,7 +140,15 @@ const LumeProvider = ({ children }) => {
return ( return (
<LumeContext.Provider <LumeContext.Provider
value={{ lume, ready, setReady, isLoggedIn, setIsLoggedIn }}> value={{
lume,
ready,
setReady,
isLoggedIn,
setIsLoggedIn,
inited,
setInited,
}}>
{children} {children}
</LumeContext.Provider> </LumeContext.Provider>
); );