Description
Originally filed by @DanielSWolf via facebook/react/issues/11031
Do you want to request a feature or report a bug?
I'd like to request documentation. :-)
When you pass null
as value
of an input, you get the following warning:
warning.js:33 Warning:
value
prop onselect
should not be null. Consider using the empty string to clear the component orundefined
for uncontrolled components.
This warning very clearly states what to do. My problem is, it fails to mention why I'm not supposed to pass null
. Nor could I find any explanation online:
- I found a link to http://facebook.github.io/react/tips/controlled-input-null-value.html. The URL (...controlled-input-null-value...) sounds as if this page should explain exactly what I'm looking for. But it merely redirects to https://reactjs.org/docs/forms.html, which doesn't mention
null
. - The issue "Warn when input's value is null" states that this warning should be added, but doesn't say why.
- The (open) pull request "Document that
value={undefined}
is not controlled component" adds the following documentation: "Similarly to not setting thevalue
attribute at all, setting it tonull
orundefined
will make React assume the component is not controlled and may produce a warning." But again, there is no explanation as to why React behaves this way.
Naively, I'd expect null
to be a perfectly valid value, e.g. for a numeric input that is empty. Passing an empty string to indicate the absence of a numeric value seems odd to me. So I'd really like some more information in the documentation!