aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/RootStoreProvider.tsx
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-10-07 19:44:41 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-11-05 19:41:14 +0100
commitabe176d0888c0fdcc803ddafe71a5cee9f4b63a0 (patch)
treeea7d5722c8e981ba540e648fbacbfd0e4a55768a /subprojects/frontend/src/RootStoreProvider.tsx
parentfix: test and lint failures (diff)
downloadrefinery-abe176d0888c0fdcc803ddafe71a5cee9f4b63a0.tar.gz
refinery-abe176d0888c0fdcc803ddafe71a5cee9f4b63a0.tar.zst
refinery-abe176d0888c0fdcc803ddafe71a5cee9f4b63a0.zip
refactor(frontend): improve HMR experience
Use a HMR acceptor as in https://github.com/vitejs/vite/issues/10227#issuecomment-1256969751 Also updates frontend tooling to the latest version (yarn now support typescript 4.8.4)
Diffstat (limited to 'subprojects/frontend/src/RootStoreProvider.tsx')
-rw-r--r--subprojects/frontend/src/RootStoreProvider.tsx29
1 files changed, 29 insertions, 0 deletions
diff --git a/subprojects/frontend/src/RootStoreProvider.tsx b/subprojects/frontend/src/RootStoreProvider.tsx
new file mode 100644
index 00000000..70ac7776
--- /dev/null
+++ b/subprojects/frontend/src/RootStoreProvider.tsx
@@ -0,0 +1,29 @@
1import React, { type ReactNode, createContext, useContext } from 'react';
2
3import type RootStore from './RootStore';
4
5const StoreContext = createContext<RootStore | undefined>(undefined);
6
7export function useRootStore(): RootStore {
8 const rootStore = useContext(StoreContext);
9 if (!rootStore) {
10 throw new Error('useRootStore must be used within RootStoreProvider');
11 }
12 return rootStore;
13}
14
15export default function RootStoreProvider({
16 children,
17 rootStore,
18}: {
19 children?: ReactNode;
20 rootStore: RootStore;
21}): JSX.Element {
22 return (
23 <StoreContext.Provider value={rootStore}>{children}</StoreContext.Provider>
24 );
25}
26
27RootStoreProvider.defaultProps = {
28 children: undefined,
29};