diff options
Diffstat (limited to 'language-web/src/main/js/RootStore.tsx')
-rw-r--r-- | language-web/src/main/js/RootStore.tsx | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/language-web/src/main/js/RootStore.tsx b/language-web/src/main/js/RootStore.tsx new file mode 100644 index 00000000..2159f440 --- /dev/null +++ b/language-web/src/main/js/RootStore.tsx | |||
@@ -0,0 +1,28 @@ | |||
1 | |||
2 | import React, { createContext, useContext } from 'react'; | ||
3 | |||
4 | import EditorStore from './editor/EditorStore'; | ||
5 | |||
6 | export default class RootStore { | ||
7 | editorStore; | ||
8 | |||
9 | constructor() { | ||
10 | this.editorStore = new EditorStore(); | ||
11 | } | ||
12 | } | ||
13 | |||
14 | const StoreContext = createContext<RootStore | undefined>(undefined); | ||
15 | |||
16 | export const RootStoreProvider: React.FC<{ rootStore: RootStore }> = ({ children, rootStore }) => ( | ||
17 | <StoreContext.Provider value={rootStore}> | ||
18 | {children} | ||
19 | </StoreContext.Provider> | ||
20 | ); | ||
21 | |||
22 | export const useRootStore = () => { | ||
23 | const rootStore = useContext(StoreContext); | ||
24 | if (!rootStore) { | ||
25 | throw new Error('useRootStore must be used within RootStoreProvider'); | ||
26 | } | ||
27 | return rootStore; | ||
28 | }; | ||