blob: 1c3aab2b6505c744239840298ea9c7477cc660a6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import React, { createContext, useContext } from 'react';
import { EditorStore } from './editor/EditorStore';
export class RootStore {
editorStore;
constructor() {
this.editorStore = new EditorStore();
}
}
const StoreContext = createContext<RootStore | undefined>(undefined);
export const RootStoreProvider: React.FC<{ rootStore: RootStore }> = ({ children, rootStore }) => (
<StoreContext.Provider value={rootStore}>
{children}
</StoreContext.Provider>
);
export const useRootStore = (): RootStore => {
const rootStore = useContext(StoreContext);
if (!rootStore) {
throw new Error('useRootStore must be used within RootStoreProvider');
}
return rootStore;
};
|