mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
20 lines
709 B
TypeScript
20 lines
709 B
TypeScript
|
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>;
|
||
|
};
|