0

I am totally new to React Native. I have a textinput area, I want users to clear the text they have entered completely by clicking on a button. React native provides clearButtonMode, but that is only for iOS. Looking for a solution on android devices. Here is my textinput..

<View style={editProfileStyle.textinputView}>
            <TextInput
              underlineColorAndroid={"rgba(0,0,0,0)"}
              style={editProfileStyle.textInput}
              placeholder="Enter your Name"
              value={this.state.name}
              onChangeText={name => this.setState({ name: name })}
            />
          </View>
Rak1994
  • 65
  • 2
  • 11

1 Answers1

1

You have two option :


  1. You can simply change the state.name to empty string (ie : this.setState({name : ''})
  2. Based on RN docs , You can use clear() , You have first need to get reference to your TextInput <TextInput ref={input => { this.textInput = input }} /> and then when you need to clear you text use : this.textInput.clear()
ikerfah
  • 2,612
  • 1
  • 11
  • 18
  • first option clears text while I am editing. Which is not a proper method. And I did not understand the second option clearly.. can you please give an example? – Rak1994 Mar 23 '19 at 06:47
  • 1
    For the first one : you should use it when the clear button clicked, This will clear you text when the button clicked and not when you typing , for the second one : in the same method you replace this.setStat() from first solution with : this.textInput.clear() – ikerfah Mar 23 '19 at 08:20