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

后端 未结 3 2255
眼角桃花
眼角桃花 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:16

    If your state is initialized with props.value being null React will consider your Checkbox component to be uncontrolled.

    Try setting your initial state so that value is never null.

    this.state = { value: props.value || "" };
    

提交回复
热议问题