UNPKG

1.25 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2013-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 */
8
9'use strict';
10
11var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
12
13var warning = require('fbjs/lib/warning');
14
15var didWarnValueNull = false;
16
17function handleElement(debugID, element) {
18 if (element == null) {
19 return;
20 }
21 if (element.type !== 'input' && element.type !== 'textarea' && element.type !== 'select') {
22 return;
23 }
24 if (element.props != null && element.props.value === null && !didWarnValueNull) {
25 process.env.NODE_ENV !== 'production' ? warning(false, '`value` prop on `%s` should not be null. ' + 'Consider using the empty string to clear the component or `undefined` ' + 'for uncontrolled components.%s', element.type, ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
26
27 didWarnValueNull = true;
28 }
29}
30
31var ReactDOMNullInputValuePropHook = {
32 onBeforeMountComponent: function (debugID, element) {
33 handleElement(debugID, element);
34 },
35 onBeforeUpdateComponent: function (debugID, element) {
36 handleElement(debugID, element);
37 }
38};
39
40module.exports = ReactDOMNullInputValuePropHook;
\No newline at end of file