-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Warn when input's value is null #5013
Comments
(see also #2533) To be clear, we should treat null as the empty string eventually regardless of if we have a warning. Makes sense to preserve behavior for a release though. |
Yep, ok, :agree:. |
@jimfb & @spicyj Hello all, I thought of giving the pull request for this issue; If my understanding is correct, you expect an warning message needs to be printed, when the input DOM element gets its value as Sorry if its very noob question, thanks for your help. |
@antoaravinth Sounds roughly correct to me. You'll want to do the same thing for |
@jimfb: Thanks for your response. Will give a PR probably in a day. |
@antoaravinth You may find this diff very helpful, since it's almost exactly what you're trying to do: https://github.com/facebook/react/pull/5032/files For the warning message, we should say something like:
Also, just fyi, we're in a code freeze 0.14 so your change will land when we're ready to merge 0.15 stuff. You're welcomed to take a stab at it now, but will likely need to rebase once we're ready to merge 0.15 stuff. |
@jimfb : Thanks for your help. Will do the same and give an PR in a day or so. Will rebase if necessary for 0.15 release, that shouldn't be a problem. |
@jimfb : Actually I made the changes for
|
@antoaravinth That error is basically saying that the test wasn't expecting any warnings to fire, but some warnings were printed. You can either add some checks for the warnings (as I did in my linked diff above) or you can modify the test such that it doesn't warn (eg. update the test to pass |
@jimfb Thanks for your help, I have given a PR ( https://github.com/facebook/react/pull/5048/files ). Let me know if anything else needed from my side. |
Fixed in #5048 Thanks @antoaravinth! |
This change in React facebook/react#5013 causes the warning message if the value of an input is null.
This change in React facebook/react#5013 causes the warning message if the value of an input is null.
This change in React facebook/react#5013 causes the warning message if the value of an input is null.
This change in React facebook/react#5013 causes the warning message if the value of an input is null.
So... why is this a thing? I do the suggested workaround |
I think the first post is a bit misleading. There's no problem with null as a value. The problem is React treats this as a flag to make an input uncontrolled. That turned out to be confusing. So we added a warning to discourage existing users from passing null. This lets us safely change the behavior for future version to treat null as an empty string. We haven't done this yet but that's the plan, if I understand it right. Maybe now is a good time to do this. Do you mind raising a new issue to discuss? |
@gaearon will do, thx. |
Using defaultValue attribute worked for me in case of onblur. |
@agnihotriketan defaultValue does work fine, but it's intended for uncontrolled inputs. If you're using controlled inputs, this is a workaround at best, IMO. |
However we solve this issue, I really want to have a less hacky way of passing |
Passing
null
indicates that the user tried to specify a value (eg. from the database) but didn't notice the value was null; seems like that should be a warning. Normally we treat null and undefined as the same, but in this case passing null indicates an error and should therefore be discouraged. The user should decide if they want an uncontrolled component (in which case they should pass undefined) or if they want an empty controlled component (in which case they should pass the empty string).@spicyj said he would be fine with this being a warning and/or with treating null as an empty string. Making it an error/warning has the advantage that there is now an easy upgrade path (fix the warning) without us introducing subtle changes in behavior that will break people's apps.
The text was updated successfully, but these errors were encountered: