react-native-actionsheet
react-native-actionsheet copied to clipboard
get selectedValue not only the index
Hi, I am using react-native-actionsheet to show dropdown in iOS, I was able to get the selected index, however, I don't know what is the syntax to get the selected value also.
showActionSheet = () => {
this.ActionSheet.show()
}
handlePress = (buttonIndex, option) => {
this.setState({ selected: buttonIndex, Region: options})
}
<Text style={styles.inputfields} onPress={this.showActionSheet}>Region</Text>
<ActionSheet
ref={o => this.ActionSheet = o}
title={'Region'}
options={['east', 'west', 'north', 'south', 'Cancel']}
cancelButtonIndex={5}
selectedValue={this.state.Region}
value={this.state.Region}
onPress={this.handlePress}
/>
Store your options in a variable then you can access it with the selected index:
const options = ['east', 'west', 'north', 'south', 'Cancel'];
const handlePress = (index) => {
console.log(index, options[index]);
};
<ActionSheet
options={options}
onPress={handlePress}
...
/>