Do you guys see anything wrong with this code?

I have been trying to fix this onClick function in react and it just doesnt run, and I cant figure out why.

constructor(props){
  super(props);
  this.state = {
    count : true
  }

  this.handleChange = this.handleChange.bind(this);
}

handleChange(event){

  this.setState((state, props) => {
  return {count: !this.state.count};
  console.log("state changed");
}
);  
}

and then inside the render method

<div class="custom-control custom-switch">
              <input onClick={this.handleChange} type="checkbox" class="custom-control-input" id="customSwitch1"></input>
              <label class="custom-control-label" htmlFor="customSwitch1">Tema</label>
              </div>

Put console.log("state changed"); before the return statement :slight_smile:

2 Likes