React Checkbox not sending onChange

后端 未结 7 1404
夕颜
夕颜 2020-12-04 16:19

TLDR: Use defaultChecked instead of checked, working jsbin.

Trying to setup a simple checkbox that will cross out its label text when it is checked. For some reason

7条回答
  •  醉酒成梦
    2020-12-04 16:36

    If you have a handleChange function that looks like this:

    handleChange = (e) => {
      this.setState({
        [e.target.name]: e.target.value,
      });
    }
    

    You can create a custom onChange function so that it acts like an text input would:

     {
        this.handleChange({
          target: {
            name: e.target.name,
            value: e.target.checked,
          },
        });
      }}
    />
    

提交回复
热议问题