React a component is changing an uncontrolled input of type checkbox to be controlled

后端 未结 3 2241
眼角桃花
眼角桃花 2021-02-19 06:33

react gives me a warning: \"A component is changing an uncontrolled input of type checkbox to be controlled. Input elements should not switch from uncontrolled to controlled (or

3条回答
  •  借酒劲吻你
    2021-02-19 07:21

    If you are using a checkbox react won't like a string either so instead try

    this.state = { checkboxValue: props.checkboxValue || false };
    

提交回复
热议问题