Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get selectedValue not only the index #100

Open
aasalshehhi opened this issue Jan 19, 2020 · 1 comment
Open

get selectedValue not only the index #100

aasalshehhi opened this issue Jan 19, 2020 · 1 comment

Comments

@aasalshehhi
Copy link

aasalshehhi commented Jan 19, 2020

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}
    />
@pistou
Copy link

pistou commented Apr 9, 2020

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}
    ...
    />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants