How to set default Checked in checkbox ReactJS?

前端 未结 16 1924
难免孤独
难免孤独 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:27

    If someone wants to handle dynamic data with multiple rows, this is for 
    handing dynamic data. 
    You can check if the rowId is equal to 0.
    If it is equal to 0, then you can set the state of the boolean value as true.
    interface MyCellRendererState {
        value: boolean;
    }
    constructor(props) {
            super(props);
            this.state = {
                value: props.value ? props.value : false
            };
            this.handleCheckboxChange = this.handleCheckboxChange.bind(this);
        }
    handleCheckboxChange() {
            this.setState({ value: !this.state.value });
        };
    render() {
            const { value } = this.state;
            const rowId = this.props.rowIndex
            if (rowId === 0) {
               this.state = {
                 value : true }
            }
            return ( 
              
    ) }

提交回复
热议问题