I am storing user text input into states like so
<TextInput
placeholder = "Hello"
onChangeText = {(text) => this.setState({greeting: text})}
/>
I want to do a similar thing using react-native-modal-dropdown.
<ModalDropdown
style = {styles.enterSearch}
options = {this.state.gasOptions}
onSelect {(renderButtonText) => this.setState({gas: renderButtonText})}
/>
With this code I can select what option I want but I cannot find a way to get the value of the text option selected.
Any help would be great.
I am storing user text input into states like so
<TextInput
placeholder = "Hello"
onChangeText = {(text) => this.setState({greeting: text})}
/>
I want to do a similar thing using react-native-modal-dropdown.
<ModalDropdown
style = {styles.enterSearch}
options = {this.state.gasOptions}
onSelect {(renderButtonText) => this.setState({gas: renderButtonText})}
/>
With this code I can select what option I want but I cannot find a way to get the value of the text option selected.
Any help would be great.
Share Improve this question edited Jul 10, 2018 at 21:22 paulgio asked Jul 10, 2018 at 21:04 paulgiopaulgio 7222 gold badges8 silver badges23 bronze badges1 Answer
Reset to default 5For some reason you have to put String in front of the value for it to actually read it correctly. This took me a while to figure out so I hope it helps someone else out.
<ModalDropdown
style = {styles.enterSearch}
options = {this.state.gasOptions}
onSelect {(value) => this.setState({gas: (String(this.state.gasOptions[value]))})}
/>