Since change events are fired for input in some browsers only (namely IE) only when the focus is lost, my understanding is that the click event is a better way to listen for changes (see Getting value of HTML Checkbox from onclick/onchange events
).
However, when I only supply only the checked property with an onClick handler to a controlled input element in react, it complains with:
Warning: Failed prop type: You provided a `checked` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultChecked`. Otherwise, set either `onChange` or `readOnly`.
What is the solution here? The react documentation seems to suggest using onChange, but that conflicts with the recommendations in the answer listed above.
onChangewould behave like you would expect on a modern browser. I would just useonChangeinstead of worrying about it yourself unless you can test it yourself.