I can not figure out if I am missing something small here?
Just trying to get a grasp on how state works with React.
Just creating a small check box that change
Changes:
1. You forgot to bind the onChange
method, either use this:
onChange={this.handleCheck.bind(this)}
or define the binding in the constructor
:
this.handleCheck = this.handleCheck.bind(this)
2. You used setState
in a wrong way, setState is a method you need to call it.
Instead of: this.setState = ({})
it should be: this.setState({})
Binding your handleCheck
function in the constructor:
constructor(props) {
super(props);
this.state = {
checked: true
};
this.handleCheck = this.handleCheck.bind(this);
}