mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
20 lines
651 B
TypeScript
20 lines
651 B
TypeScript
|
import { ReactElement, createContext } from "react";
|
||
|
// mobx store
|
||
|
import { RootStore } from "@/store/root.store";
|
||
|
|
||
|
let rootStore = new RootStore();
|
||
|
|
||
|
export const StoreContext = createContext<RootStore>(rootStore);
|
||
|
|
||
|
const initializeStore = () => {
|
||
|
const singletonRootStore = rootStore ?? new RootStore();
|
||
|
if (typeof window === "undefined") return singletonRootStore;
|
||
|
if (!rootStore) rootStore = singletonRootStore;
|
||
|
return singletonRootStore;
|
||
|
};
|
||
|
|
||
|
export const StoreProvider = ({ children }: { children: ReactElement }) => {
|
||
|
const store = initializeStore();
|
||
|
return <StoreContext.Provider value={store}>{children}</StoreContext.Provider>;
|
||
|
};
|