aboutsummaryrefslogtreecommitdiffstats
path: root/language-web/src/main/js/RootStore.tsx
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <marussy@mit.bme.hu>2021-08-22 19:54:51 +0200
committerLibravatar Kristóf Marussy <marussy@mit.bme.hu>2021-08-22 19:54:51 +0200
commit8cbf8fdcfdceab8a330bdc82e4260a55c125c37d (patch)
tree0354dcc6ce0704fc953e7665ecfcc700609549a2 /language-web/src/main/js/RootStore.tsx
parentBump Material-UI version (diff)
downloadrefinery-8cbf8fdcfdceab8a330bdc82e4260a55c125c37d.tar.gz
refinery-8cbf8fdcfdceab8a330bdc82e4260a55c125c37d.tar.zst
refinery-8cbf8fdcfdceab8a330bdc82e4260a55c125c37d.zip
Covert language-web to TypeScript
Diffstat (limited to 'language-web/src/main/js/RootStore.tsx')
-rw-r--r--language-web/src/main/js/RootStore.tsx28
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
2import React, { createContext, useContext } from 'react';
3
4import EditorStore from './editor/EditorStore';
5
6export default class RootStore {
7 editorStore;
8
9 constructor() {
10 this.editorStore = new EditorStore();
11 }
12}
13
14const StoreContext = createContext<RootStore | undefined>(undefined);
15
16export const RootStoreProvider: React.FC<{ rootStore: RootStore }> = ({ children, rootStore }) => (
17 <StoreContext.Provider value={rootStore}>
18 {children}
19 </StoreContext.Provider>
20);
21
22export 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};