I using reactjs and semantic ui and want to call a OnChange function on input checkbox:
App.js
getChecked = (e) => {
if(e.target.checked === true){
this.setState({
rent: '1'
});
} else {
this.setState({
rent: '0'
});
}
console.log(e);
};
..
<Input onChange={this.getChecked} type="checkbox" name="isRent" id="isRent" value={this.state.rent}/>
This code working perfectly JSFiddle
But when I use checkbox class from semantic ui on this input, onChange function not working anymore JSFiddle
Before:
<input type="checkbox" onChange={this.getChecked}/>
After:
<div className="ui slider checkbox">
<input type="checkbox" onChange={this.getChecked}/>
</div>
Any idea for why it now working?
$('.checkbox').checkbox();probably jQuery adding its own handler to it and so ignoring you function. Don't use jQuery anymore!