-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathMainChakra.tsx
More file actions
69 lines (64 loc) · 2.08 KB
/
MainChakra.tsx
File metadata and controls
69 lines (64 loc) · 2.08 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/// <reference path='../../../../typings/index.d.ts' />
import * as React from 'react';
import { ApolloProvider } from '@apollo/client';
import { Provider } from 'react-redux';
import { ConnectedRouter } from 'connected-react-router';
import { PersistGate } from 'redux-persist/integration/react';
import { persistStore } from 'redux-persist';
import { createBrowserHistory } from 'history';
import { HelmetProvider } from 'react-helmet-async';
import { CacheProvider } from '@emotion/react';
import createEmotionCache from '../common/createEmotionCache';
import { createReduxStore } from '../config/redux-config';
import { createClientContainer } from '../config/client.service';
import modules, { MainRoute } from '../modules';
const { apolloClient: client } = createClientContainer();
const history = createBrowserHistory();
const { store } = createReduxStore(history);
const WithChakra = () => {
if (__CHAKRA__) {
const cache = createEmotionCache();
return (
<CacheProvider value={cache}>
{modules.getWrappedRoot(
<ConnectedRouter history={history}>
<MainRoute />
</ConnectedRouter>,
)}
</CacheProvider>
);
} else {
return
modules.getWrappedRoot(
<ConnectedRouter history={history}>
<MainRoute />
</ConnectedRouter>,
);
}
}
const WithPersistGate = () => {
let persistor = persistStore(store);
if (__SSR__) {
return (
<PersistGate loading={null} persistor={persistor}>
{() => <WithChakra />}
</PersistGate>
);
} else {
return (
<PersistGate persistor={persistor}>
<WithChakra />
</PersistGate>
);
}
}
const Main = () => (
<HelmetProvider>
<Provider store={store}>
<ApolloProvider client={client}>
<WithPersistGate />
</ApolloProvider>
</Provider>
</HelmetProvider>
);
export default Main;