jeudi 2 mars 2017

React how to change checkbox from true to false if checkbox clicked

As the title says I want to change value of checkbox from true to false or false to true when clicked. I'm not sure how to change it. I'm presuming "setState" but how exactly I am not sure

toggleCheckboxChange(e) {

let isState = e.target.value;


if(isState != false) {
   isTrue = isState
}
if(isState == false) {
  isTrue = isState;
}
  //change state of checkbox
}
  render() {

weatherInfo = <WeatherInfo
      nameOfCity={nameOfCity}
      weatherDescription={weatherDescription}
      windSpeed={windSpeed}
      temperature={temperature}
      maxTemperature={maxTemperature}
      minTemperature={minTemperature}
      myPokemon={myPokemon}
      change={this.toggleCheckboxChange.bind(this)}
  />;


const WeatherInfo = (props) => (
<div>
    <ul>
        <li>{props.nameOfCity}</li>
        <li>{props.weatherDescription}</li>
        <li>{props.windSpeed} m/s </li>
        <li>{props.temperature} °C</li>
        <li>{props.maxTemperature}°C</li>
        <li>{props.minTemperature}°C</li>

        <input
            type="checkbox"
            value={false}
            onChange={(e)=>props.change(e)}
        />
    </ul>
</div>
);




Aucun commentaire:

Enregistrer un commentaire