我想知道如何切换React组件的布尔状态.例如:
我在组件的构造函数中进行了布尔状态判断:
constructor(props, context) {
super(props, context);
this.state = {
check: false
};
};
每次单击复选框时,我都会try 使用this.setState
方法切换状态:
<label>
<input
type=checkbox"
value="check"
onChange={(e) => this.setState({check: !check.value})}
/>
Checkbox
</label>
我当然得了Uncaught ReferenceError: check is not defined分.