3

I'm new to react native. I have made dropdown list but i want one reset button whenever i click it reset the default label. Here is my code of simple dropown list.I want one reset button.

<Picker
  style={{width:'80%'}}
  selectedValue={this.state.PickerValue}
  onValueChange={(itemValue,itemIndex) => 
  this.setState({PickerValue:itemValue})}>
    <Picker.Item label="Select a option" value=""/>
    <Picker.Item label="Html" value="html" />
    <Picker.Item label="Javascript" value="javascript"/>
</Picker>
martwetzels
  • 437
  • 5
  • 19
shabnam singh
  • 107
  • 1
  • 10

1 Answers1

2

While I have no experience with Picker, setting the value of your dropdown using a button can be done by doing this:

setDropdownValue = () => {
    document.getElementById("languagePicker").selectedIndex = "0";
};

<button onClick={this.setDropdownValue}>Reset selected picker value</button>

Dont forget to replace:

<Picker
to
<Picker id="languagePicker"
Craws
  • 576
  • 4
  • 30