Reputation: 29
export default class App extends Component<Props> {
constructor() {
super();
this.state = {
value: "Edit me!"
};
this.handleChangeText = this.handleChangeText.bind(this);
}
handleChangeText(newText) {
this.setState({
value: newText
});
}
render() {
return (
<View style={styles.container}>
<TextInput style={styles.editText}
onChange={this.handleChangeText}/>
<Text>hello {this.state.value}</Text>
</View>
);
}
I am new to react native. I am getting error on hello {this.state.value} line. How can i solve this. Please help me
Upvotes: 1
Views: 64
Reputation: 625
Can you try this?
export default class App extends Component<Props> {
constructor(Props) {
super(props);
this.state = {
value: "Edit me!"
};
}
handleChangeText = (newText) => {
this.setState({
value: newText
});
}
render() {
return (
<View style={styles.container}>
<TextInput
style={styles.editText}
onChangeText={this.handleChangeText}
/>
<Text>hello {this.state.value}</Text>
</View>
);
}
}
Upvotes: 2