-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
55 lines (48 loc) · 1.02 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
47
48
49
50
51
52
53
54
55
import React, { Component } from 'react'
import {AppRegistry, Picker} from 'react-native'
import {connect} from 'react-redux'
function mapStateToProps (state) {
return {
value: state.value
}
}
function mapDispatchToProps (dispatch) {
return {
setValue: value => dispatch({type:'SET_VALUE', value})
}
}
@connect(mapStateToProps, mapDispatchToProps)
export default class App extends Component {
onValueChange = value => {
console.log(value, this.props.value)
this.props.setValue(value)
}
values = [
'first value',
'second value',
'third value',
'fourth value'
]
makeNodes = function * () {
for (let i in this.values) {
yield (
<Picker.Item
label={this.values[i]}
key={i}
value={i}
/>
)
}
}
render () {
return (
<Picker
selectedValue={this.props.value}
onValueChange={this.onValueChange}
mode='dropdown'
>
{[...this.makeNodes()]}
</Picker>
)
}
}