blob: eb1be7a5563db1122acfb38827ebd17010ce635a (
plain)
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
|
import React, { useContext } from 'react';
import App from './app';
export interface IAppContext {
app: App;
}
export const AppContext = React.createContext<IAppContext | undefined>(undefined);
if (window.env.development) {
AppContext.displayName = 'AppContext';
}
const missingContextError = new Error(
'The context value is empty. Make sure to wrap the component in AppContext.Provider.',
);
export function useAppContext(): App {
const appContext = useContext(AppContext);
if (appContext) {
return appContext.app;
} else {
throw missingContextError;
}
}
|