i keep having the same error. don't know why ?
the error is: Uncaught TypeError: Cannot read property 'props' of null
i know that the error happens when i click the button. specifically i think it's in the update() method.
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component{
constructor(){
super();
this.state = {increasing:false}
this.do_update = this.update.bind(this);
}
update(){
ReactDOM.render(
<App val={this.props.val+1} />,
document.getElementById('app')
);
}
componentWillReceiveProps(nextProps){
this.setState({increasing: (nextProps.val > this.props.val) })
}
render(){
return <button onClick={this.update}>{this.props.val}</button>
}
}
App.defaultProps = {val:0}
ReactDOM.render(<App />,document.getElementById('app'))
In this case you need pass to onClick do_update instead of update,
return <button onClick={ this.do_update }>{ this.props.val }</button>
or change name from do_update to update
this.update = this.update.bind(this);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With