考虑以下某些组件的功能:
handleInputChange(e) {
// let val = e.target.value; - if I uncomment this, it works.
// Update text box value
this.setState(function (prevState, props) {
return {
searchValue: e.target.value,
}
})
}
和一个文本框,由上述组件的子组件呈现,并接收handleInputChange为props:
<input type="text" onChange={that.props.handleInputChange} value={that.props.searchValue} />
当我在文本字段中输入内容时,我收到错误消息Cannot read property 'value' of null。
如果我取消注释handleInputChange函数内部的第一行,我将文本框值存储在val变量中,它运行良好。想法为什么?