score:0

// @ parent component

handleChange(evt) {
  // NOTE: i'm going to ignore the evt, since I don't need it.

  // NOTE: i'm going to use optional callback given by setState, to access prevState, and toggle the checked state boolean value.
  this.setState((prevState) => ({ checked: !prevState.checked }));
}

score:0

handleChange(checked) {
  this.setState({ checked:!checked });
}

score:1

function TSwitch(props) {

  return (
    <div>
      {props.house.map((house) => {
        return (
          <label>
            <span>Switch with default style</span>
            <Switch onChange={x => props.handleChange(x)} checked={props.isChecked} />
          </label>
        );
      })}
    </div>
  );
}

Related Query

More Query from same tag