【发布时间】:2022-01-13 11:43:41
【问题描述】:
考虑以下某些组件的功能:
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 变量中,它运行良好。想法为什么?
【问题讨论】:
标签: javascript reactjs