I\'d like to know how to toggle a boolean state of a react component. For instance:
I have boolean state check in the constructor of my component:
const
Use checked to get the value. During onChange, checked will be true and it will be a type of boolean.
checked
onChange
true
boolean
Hope this helps!
class A extends React.Component { constructor() { super() this.handleCheckBox = this.handleCheckBox.bind(this) this.state = { checked: false } } handleCheckBox(e) { this.setState({ checked: e.target.checked }) } render(){ return } } ReactDOM.render(, document.getElementById('app'))