React: Missing documentation: null/undefined as input value

Created on 2 Oct 2017  路  3Comments  路  Source: facebook/react

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 on select should not be null. Consider using the empty string to clear the component or undefined 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:

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!

All 3 comments

Sorry about the confusing redirects. We rewrote the docs last year and did best effort redirects, but it's worth updating some of the warnings to better locations.

If I recall it right, the reason for this warning is just because we wanted to change the behavior for null. So not using it ensures your code won't break when we do change it. We haven't changed it yet.

Thank you for filing this issue! 馃槃

The documentation and source code for reactjs.org now lives in a different repository: reactjs/reactjs.org. (For more info on why we made this move, see issue #11075.)

I've moved your issue to the new repo: reactjs/reactjs.org#16

Let's continue the discussion there! Sorry for the inconvenience.

If I recall it right, the reason for this warning is just because we wanted to change the behavior for null. So not using it ensures your code won't break when we do change it. We haven't changed it yet.

Is there a reason this is still the case? I think it's a strange rule as it's normal to use null as _explicitly_ not a value, as opposed to undefined which means _does not exist_ and react enforces null as a return value when explicitly not returning a component.

Was this page helpful?
0 / 5 - 0 ratings