aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/RootStore.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/src/RootStore.tsx')
-rw-r--r--subprojects/frontend/src/RootStore.tsx39
1 files changed, 39 insertions, 0 deletions
diff --git a/subprojects/frontend/src/RootStore.tsx b/subprojects/frontend/src/RootStore.tsx
new file mode 100644
index 00000000..baf0b61e
--- /dev/null
+++ b/subprojects/frontend/src/RootStore.tsx
@@ -0,0 +1,39 @@
1import React, { createContext, useContext } from 'react';
2
3import { EditorStore } from './editor/EditorStore';
4import { ThemeStore } from './theme/ThemeStore';
5
6export class RootStore {
7 editorStore;
8
9 themeStore;
10
11 constructor(initialValue: string) {
12 this.themeStore = new ThemeStore();
13 this.editorStore = new EditorStore(initialValue, this.themeStore);
14 }
15}
16
17const StoreContext = createContext<RootStore | undefined>(undefined);
18
19export interface RootStoreProviderProps {
20 children: JSX.Element;
21
22 rootStore: RootStore;
23}
24
25export function RootStoreProvider({ children, rootStore }: RootStoreProviderProps): JSX.Element {
26 return (
27 <StoreContext.Provider value={rootStore}>
28 {children}
29 </StoreContext.Provider>
30 );
31}
32
33export const useRootStore = (): RootStore => {
34 const rootStore = useContext(StoreContext);
35 if (!rootStore) {
36 throw new Error('useRootStore must be used within RootStoreProvider');
37 }
38 return rootStore;
39};