I would like to use a picker to select countries:
export default class RegisterMobile extends Component {
constructor(props) {
super(props)
this.state = {
country: 'india',
}
}
changeCountry = (c) => {
this.setState({
country: c,
})
console.log(this.state.country);
}
render() {
return(
<View style={styles.container}>
<View style={styles.selectCountry}>
<Picker selectedValue={this.state.country} onValueChange={this.changeCountry}>
<Picker.Item label="India" value="india" />
<Picker.Item label="China" value="china" />
</Picker>
</View>
</View>
)
}
}
this.state.country
this.state.country
this.setState call is not a synchronous process. calling setState put it an update batch. Your console.log statement should be called in callback argument of setState:
this.setState({country: c,},
()=>{ console.log(this.state.country)}
)
See setState doc