Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript React.JS无法读取属性';道具';零误差 刚开始使用react.js_Javascript_Reactjs - Fatal编程技术网

Javascript React.JS无法读取属性';道具';零误差 刚开始使用react.js

Javascript React.JS无法读取属性';道具';零误差 刚开始使用react.js,javascript,reactjs,Javascript,Reactjs,我总是犯同样的错误。不知道为什么 错误为:uncaughttypeerror:无法读取null的属性“props” 我知道当我点击按钮时会发生错误。具体地说,我认为它在update()方法中 JS代码: 从“React”导入React; 从“react dom”导入react dom; 类应用程序扩展了React.Component{ 构造函数(){ 超级(); this.state={递增:false} this.do_update=this.update.bind(this); } 更新()

我总是犯同样的错误。不知道为什么
错误为:
uncaughttypeerror:无法读取null的属性“props”

我知道当我点击按钮时会发生错误。具体地说,我认为它在update()方法中

JS代码:
从“React”导入React;
从“react dom”导入react dom;
类应用程序扩展了React.Component{
构造函数(){
超级();
this.state={递增:false}
this.do_update=this.update.bind(this);
}
更新(){
ReactDOM.render(
,
document.getElementById('app')
);
}
组件将接收道具(下一步){
this.setState({递增:(nextrops.val>this.props.val)})
}
render(){
返回{this.props.val}
}
}
App.defaultProps={val:0}
ReactDOM.render(,document.getElementById('app'))

在这种情况下,您需要传递到
onClick
do\u update
,而不是
update

return <button onClick={ this.do_update }>{ this.props.val }</button>

调用更新处理程序时,将无法获取“this”关键字的正确上下文。。。这就是您的代码可能具有以下特性的原因:

this.do_update = this.update.bind(this);
线路

如果将渲染方法更改为以下方式,则该方法应能正常工作:

render(){
        return <button onClick={this.do_update}>{this.props.val}</button>
    }
render(){
返回{this.props.val}
}

将此行
this.state={increating:false}
更改为
this.state={increating:false}


冒号后面的空格很重要

将渲染方法中的{this.update}更改为{this.do_update}为什么从不使用
this.do_update
?要更新状态时,请使用this.setState({reasing:false})
this.do_update = this.update.bind(this);
render(){
        return <button onClick={this.do_update}>{this.props.val}</button>
    }