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