0
<TextInput value="test" palceholder="Enter text"></TextInput>

Here in this TextInput component if i remove the "value" attribute then user entered data is visible properly .But i can't remove this "value" attribute bacause while retrieve the data i am using this "value" attribute to place the saved value

1 Answer 1

1

TextInput is a controlled component, which means that if you want to set its value, you need to then manage its value yourself.

At its simplest, you can listen to the onChangeText event to be notified when user types into the input, and store the current value in the component state:

<TextInput
  onChangeText={currentValue => this.setState({currentValue})}
  value={this.state.currentValue}
  />

The latest value is then always available as this.state.currentValue, and you can update the value by this.setState({currentValue: yourSavedValue}).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.