【发布时间】:2021-01-09 11:33:42
【问题描述】:
我想将 TextInput 中输入的值打印到控制台。
下面是我的代码中的 sn-ps:
constructor(props) {
super(props);
this.state= {
textValue: "",
}
}
_textChange = (text) => {
this.setState({
textValue: text,
})
console.log(this.state.textValue);
}
与:
<TextInput onChange={this._textChange.bind(this)}/>
我知道我的代码有问题,但我无法弄清楚。我只想在 TextInput 中打印输入的文本以在控制台中打印
注意
I have seen this answer。我无法理解给定链接中的答案。我对 react-native 很陌生。所以请尽量用简单的方式解释一下。
【问题讨论】:
-
有什么动机在 onChange 中绑定方法?
-
你可能想这样做:
onChangeText={this._textChange}而不是使用onChange
标签: reactjs react-native