plane/web/contexts/app-root/app-root-provider.tsx

20 lines
709 B
TypeScript
Raw Normal View History

2023-12-12 20:33:29 +00:00
import { createContext } from "react";
// mobx store
import { AppRootStore, IAppRootStore } from "store/application";
let appRootStore: IAppRootStore = new AppRootStore();
export const AppRootStoreContext = createContext<IAppRootStore>(appRootStore);
const initializeStore = () => {
const _appRootStore: IAppRootStore = appRootStore ?? new AppRootStore();
if (typeof window === "undefined") return _appRootStore;
if (!appRootStore) appRootStore = _appRootStore;
return _appRootStore;
};
export const AppRootStoreProvider = ({ children }: any) => {
const store: IAppRootStore = initializeStore();
return <AppRootStoreContext.Provider value={store}>{children}</AppRootStoreContext.Provider>;
};