jeudi 7 mai 2020

Checkbox not reflecting changes in the state in ReactJS

I cannot get my reactjs component to reflect the actual changes in state on a checkbox. Could anyone kindly assist or point out what is wrong with my code below.

This is my state

 state = {
    data: {
      name: "",
      address: "",
      city: "",
      country: "",
      mobile_number: "",
      description: "",
      has_conference: false,
      star_rating: "",
    },
    errors: {},
  };

This handle checkbox method

toggleChange = () => {
    this.setState({
      has_conference: !this.state.data["has_conference"],
    });
  };

And finally the checkbox code in render method

                <label>
                <input
                  type="checkbox"
                  has_conference={this.state.data["has_conference"]}
                  onChange={this.toggleChange}
                />
                Conferencing
              </label>



Aucun commentaire:

Enregistrer un commentaire