简体   繁体   English

反应复选框不会打开 onchange

[英]React checkbox doesn't toggle on onchange

My react checkbox component will not uncheck when its clicked.我的反应复选框组件在单击时不会取消选中。

Pic of my code我的代码图片

Remove bind method from constructor because you have already make arrow function so there is no need to bind and try this.从构造函数中删除绑定方法,因为您已经制作了箭头 function,因此无需绑定并尝试此操作。

<div className={`checkbox ${this.props.color}`} onclick={this.onChange}>
    <div>
         {this.state.checked && <svg write conditional component here../>} 
    </div>
</div>

Hopefully this will work.希望这会奏效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM