-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (39 loc) · 1.47 KB
/
index.js
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
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import { createStore, applyMiddleware, compose } from "redux";
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import { PersistGate } from 'redux-persist/integration/react'
import createSagaMiddleware from "redux-saga";
import { Provider } from "react-redux";
import mainSaga from "./saga";
import reducer from "./reducers";
const sagaMiddleware = createSagaMiddleware();
const reduxDevTools =
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__();
const persistConfig = {
key: 'root',
storage,
whitelist: ['userToken', 'userId']
}
const persistedReducer = persistReducer(persistConfig, reducer)
const appliedSaga = applyMiddleware(sagaMiddleware);
let store = createStore(
persistedReducer,
reduxDevTools ? compose(appliedSaga, reduxDevTools) : appliedSaga,
);
let persistor = persistStore(store)
sagaMiddleware.run(mainSaga);
ReactDOM.render(
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<App />
</PersistGate>
</Provider>, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
serviceWorker.unregister();