How to set default Checked in checkbox ReactJS?

前端 未结 16 1987
难免孤独
难免孤独 2020-11-27 11:51

I\'m having trouble to update the checkbox state after it\'s assigned with default value checked="checked" in React.

var rCheck = React         


        
16条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 12:25

    In my case I felt that "defaultChecked" was not working properly with states/conditions. So I used "checked" with "onChange" for toggling the state.

    Eg.

    checked={this.state.enabled} onChange={this.setState({enabled : !this.state.enabled})}
    

提交回复
热议问题