-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.js
47 lines (36 loc) · 1.03 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
44
45
46
import React, { Component } from 'react';
import { NetInfo } from 'react-native';
// redux 相关
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as actionCreators from './src/redux/actions';
import Main from './src/config/router';
class ReduxRoute extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
this.checkNet();
}
// 检测网络是否连接
async checkNet() {
const netInfo = await NetInfo.getConnectionInfo();
this.props.setUserInfo({ connectNetType: netInfo.type });
NetInfo.addEventListener('connectionChange', (netInfoObj) => {
this.props.setUserInfo({ connectNetType: netInfoObj.type });
});
}
render() {
return <Main />;
}
}
// 关联 redux store
function mapStateToProps(state) {
return {
userInfo: state.reducers.userInfo,
};
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(actionCreators, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(ReduxRoute);