Reputation: 1575
<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
Upvotes: 0
Views: 490
Reputation: 35890
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})
.
Upvotes: 1