I am currently a bit lost with this - as I thought - trivial task. I have some checkboxes in my React App which have a onClick Function. Now I need to pass the info to the function, if I just checked or unchecked the checkbox.
<input type="checkbox"
name={field}
id={field}
onClick={() => this.buildTemplate(objectA, objectB, checkboxState)}
/>
<label htmlFor={field}>
{getLabel(`${this.props.modelType}.${fieldName}`)}
</label>
When the function is called, I need to do some stuff depending on the state of the checkbox.
buildTemplate = (objectA, objectB, checked) => {
checked ? yep() : nope();
};
I tried to bind the checkbox like this, and it worked, but now I dont know how to pass the other arguments in this function.
onClick={this.testFunc.bind(this)}
...
testFunc(event) {
console.log(event.target.checked)
}
I also found this question, where the accepted answer suggested refs, but I may have a lot of checkboxes, and it seems a bit overkill to me, to create refs just to pass the current state of the checkbox. I think there is a dumb solution for this, but it seems like I can't figure it out.