1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

fixed auth hydration

This commit is contained in:
Fedor Katurov 2022-01-09 19:32:37 +07:00
parent d9feff085a
commit e90f8b6888
3 changed files with 14 additions and 3 deletions

View file

@ -1,10 +1,13 @@
import React, { createContext, FC, useContext } from 'react';
import { Store } from '~/store';
import { observer } from 'mobx-react-lite';
export const StoreContext = createContext<Store>(new Store());
export const StoreContextProvider: FC<{ store: Store }> = ({ children, store }) => {
export const StoreContextProvider: FC<{ store: Store }> = observer(({ children, store }) => {
if (!store.isHydrated) return null;
return <StoreContext.Provider value={store}>{children}</StoreContext.Provider>;
};
});
export const useStore = () => useContext(StoreContext);