Reputation: 2381
I created an Input using native base, but I can't edit the value. It keep showing the same value.
render() {
const {
FirstName, LastName, Email, Phone, Unit, MiddleName
} = this.state.MyData;
...
<Input
value={LastName}
onChangeText={val => this.setState({ LastName: val })}
style={styles.valueText}
/>
...
It has the value 'Smith'. When I click on the Input, it does not allow me to delete or add characters.
Thanks
Upvotes: 0
Views: 1259
Reputation: 41
now you can use code
import React, { Component } from 'react';
import { AppRegistry, TextInput } from 'react-native';
export default class UselessTextInput extends Component {
constructor(props) {
super(props);
this.state = { text: 'Useless Placeholder' };
}
render() {
return (
<TextInput
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
onChangeText={(text) => this.setState({text})}
value={this.state.text}
/>
);
}
}
Upvotes: 0
Reputation: 16142
You are not updating the object but adding a new value to state, after typing a value into the Input your state becomes.
state = {
MyData: {...},
LastName: ...
}
Update the object instead
onChangeText = (text, input) => {
const obj = { ...this.state.MyData };
obj[input] = text;
this.setState({
MyData: obj
})
};
<Input
value={LastName}
onChangeText={(text) => this.onChangeText(text, 'LastName')}
style={styles.valueText}
/>
Upvotes: 1