-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathapp.js
More file actions
80 lines (72 loc) · 1.51 KB
/
app.js
File metadata and controls
80 lines (72 loc) · 1.51 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
70
71
72
73
74
75
76
77
78
79
80
import React from 'react'
import { TouchableHighlight, View, Text, StyleSheet } from 'react-native'
import { connect } from 'react-redux'
import { fetchData } from './actions'
let styles
const App = (props) => {
const {
container,
text,
button,
buttonText,
mainContent
} = styles
return (
<View style={container}>
<Text style={text}>Redux Examples</Text>
<TouchableHighlight style={button} onPress={() => props.fetchData()}>
<Text style={buttonText}>Load Data</Text>
</TouchableHighlight>
<View style={mainContent}>
{
props.appData.isFetching && <Text>Loading</Text>
}
{
props.appData.data.length ? (
props.appData.data.map((person, i) => {
return <View key={i} >
<Text>Name: {person.name}</Text>
<Text>Age: {person.age}</Text>
</View>
})
) : null
}
</View>
</View>
)
}
styles = StyleSheet.create({
container: {
marginTop: 100
},
text: {
textAlign: 'center'
},
button: {
height: 60,
margin: 10,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#0b7eff'
},
buttonText: {
color: 'white'
},
mainContent: {
margin: 10,
}
})
function mapStateToProps (state) {
return {
appData: state.appData
}
}
function mapDispatchToProps (dispatch) {
return {
fetchData: () => dispatch(fetchData())
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(App)