-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathMicroFrontendApp.tsx
More file actions
46 lines (39 loc) · 1.4 KB
/
MicroFrontendApp.tsx
File metadata and controls
46 lines (39 loc) · 1.4 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as React from 'react';
import { Context, withContext } from '@micro-frontend-react/core/lib/Context';
import { IDefaultState } from '@micro-frontend-react/redux/lib/IDefaultState';
import { useDynamicReducer } from '@micro-frontend-react/redux/lib/useDynamicReducer';
import { IReduxContext } from '@micro-frontend-react/redux/lib/IReduxContext';
import {
MicroFrontendActionType,
microFrontendReducer,
microFrontendSagas,
MicroFrontendState,
} from './SampleMicroFrontendReduxStore';
type AppState = IDefaultState & {
host: { hostAppName: string };
dynamic: {
microFrontend?: MicroFrontendState;
};
};
function MicroFrontendApp(): React.ReactElement {
useDynamicReducer('microFrontend', microFrontendReducer, [microFrontendSagas]);
const { useSelector, dispatch } = React.useContext(Context as React.Context<IReduxContext>);
const hostAppName = useSelector((appState: AppState) => appState.host.hostAppName);
const userName = useSelector((appState: AppState) => appState.dynamic.microFrontend?.user?.name ?? 'guest');
React.useEffect(() => {
dispatch({
type: MicroFrontendActionType.REQUEST_USER,
});
}, [dispatch]);
return (
<div
style={{
backgroundColor: '#ff6384',
}}
>
Hello {hostAppName} and {userName}, from {__APP_NAME__}
</div>
);
}
const connected = withContext(MicroFrontendApp);
export { connected as MicroFrontendApp };