-
Notifications
You must be signed in to change notification settings - Fork 287
/
AppNavigator.js
49 lines (41 loc) · 1.13 KB
/
AppNavigator.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
49
/**
* Airbnb Clone App
* @author: Andy
* @Url: https://www.cubui.com
*/
import React from 'react';
import { compose, createStore, applyMiddleware } from 'redux';
import {
reduxifyNavigator,
createReactNavigationReduxMiddleware,
} from 'react-navigation-redux-helpers';
import { createLogger } from 'redux-logger';
import thunkMiddleware from 'redux-thunk';
import { connect } from 'react-redux';
import AppRouteConfigs from './AppRouteConfigs';
import reducer from '../redux/reducers';
const middleware = createReactNavigationReduxMiddleware(
'root',
state => state.nav,
);
const App = reduxifyNavigator(AppRouteConfigs, 'root');
const mapStateToProps = state => ({
state: state.nav,
});
const AppWithNavigationState = connect(mapStateToProps)(App);
const loggerMiddleware = createLogger({ predicate: () => __DEV__ });
const configureStore = (initialState) => {
const enhancer = compose(
applyMiddleware(
middleware,
thunkMiddleware,
loggerMiddleware,
),
);
return createStore(reducer, initialState, enhancer);
};
const Root = () => <AppWithNavigationState />;
export {
configureStore,
Root,
};