Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Needless checkbox warning when using onClick instead of onChange #13171

Closed
Maaartinus opened this issue Jul 8, 2018 · 4 comments
Closed

Needless checkbox warning when using onClick instead of onChange #13171

Maaartinus opened this issue Jul 8, 2018 · 4 comments

Comments

@Maaartinus
Copy link

Do you want to request a feature or report a bug?
A very minor bug.

What is the current behavior?
When using a checkbox with onClick, I get the following 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.

But my checkbox works well and actually, onClick is the better solution according to https://stackoverflow.com/a/4471462/581205.

What is the expected behavior?
No warning when onClick is set.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
"react": "^16.4.1"

And thanks for the good software!

@jamiewinder
Copy link

Worth pointing out: much of that answer refers to a bug in Internet Explorer which was actually fixed in IE9+. React DOM doesn't support IE8 or lower any more anyway.

@jquense
Copy link
Contributor

jquense commented Jul 9, 2018

ya we have a pending PR for that: #10830

@gaearon
Copy link
Collaborator

gaearon commented Jul 17, 2018

onClick is the better solution according to https://stackoverflow.com/a/4471462/581205.

That answer doesn't apply to React. In fact React internally uses onClick precisely for that reason so you don't need to worry about it.

You can keep using onChange. While onClick is equivalent in this scenario, the warning encourages consistency so it doesn't hurt to follow it.

@gaearon gaearon closed this as completed Jul 17, 2018
@gaearon
Copy link
Collaborator

gaearon commented Jul 17, 2018

We can, however, revisit this at the same time as we merge #10830.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants