react-native-modal-picker icon indicating copy to clipboard operation
react-native-modal-picker copied to clipboard

[Need help] Any way to reset the chosen value from outside the picker?

Open Mjuk-Biltvatt opened this issue 8 years ago • 1 comments

I'd like to reset the chosen values from outside the picker. When a value is chosen in the modal picker a state is set. When the user then presses a button the values are submitted to my API. When the API then returns an OK status I want to reset the values chosen in the modal picker. This doesn't seem to happen when I pop the route.

Any ideas?

Mjuk-Biltvatt avatar Feb 28 '17 09:02 Mjuk-Biltvatt

@Mjuk-Biltvatt I did a dirty hack but for now it solves the problem: So what i did was, i created a ref in the ModalPicker, and when i'm gonna clear the data from my view, i set the state from ModalPicker and set the state from my view.

It's a dirty hack but for now is better than nothing.

Component:

            <ModalPicker
              ref={(input) => { this.test = input; }}
              data={positionsArray}
              initValue={positionsArray[0].label}
              onChange={(option) => this.setState({selectedPosition:option.key})} />
      clear=()=>{
        this.teste.setState({selected:"---"})
          this.setState({
            selectedPosition:0,
          })
      }

FlaviooLima avatar Mar 23 '17 17:03 FlaviooLima