i'm new in react and i'm notice that we use this.setState()
instead of using super.setState()
please i need clear explain why we use this to call super class method ??
example :
class Checkbox extends React.Component {
constructor(props) {
super(props)
this.state = {
checked: true
}
this.handleCheck = this.handleCheck.bind(this)
}
handleCheck() {
this.setState({
checked: !this.state.checked
})
}
render() {
var msg
if(this.state.checked) {
msg = "checked"
} else {
msg = "not checked"
}
return (
<div>
<input type="checkbox"
onChange={this.handleCheck}
defaultChecked={this.state.checked}/>
<p>This box is {msg}</p>
</div>
)
}
}