-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
43 lines (39 loc) · 1.26 KB
/
App.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
import React from "react";
import { Provider } from "react-redux";
import { View, Text, AsyncStorage } from "react-native";
import { compose, applyMiddleware, createStore } from "redux";
import logger from "redux-logger";
import { persistStore, autoRehydrate } from "redux-persist";
import { initializeAuth } from "./src/actions/authActions";
import AppReducer from "./src/reducers";
import AppWithNavigationState from "./src/navigators/AppNavigator";
import { LoadingComponent } from "./src/components/UtilityComponents/LoadingComponents";
const store = createStore(
AppReducer,
undefined,
compose(applyMiddleware(logger), autoRehydrate())
);
export default class App extends React.Component {
constructor() {
super();
this.state = { rehydrated: false };
}
componentWillMount() {
persistStore(store, { storage: AsyncStorage }, async () => {
const user = store.getState().auth.user;
const initializingAction = await initializeAuth(user);
store.dispatch(initializingAction);
this.setState({ rehydrated: true });
});
}
render() {
if (!this.state.rehydrated) {
return <LoadingComponent size="large" />;
}
return (
<Provider store={store}>
<AppWithNavigationState />
</Provider>
);
}
}