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>
1

There are 1 best solutions below

2
On

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()