UNPKG

1.37 kBJavaScriptView Raw
1/**
2 * Copyright 2013-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 *
9 */
10
11'use strict';
12
13var ReactComponentTreeHook = require('react/lib/ReactComponentTreeHook');
14
15var warning = require('fbjs/lib/warning');
16
17var didWarnValueNull = false;
18
19function handleElement(debugID, element) {
20 if (element == null) {
21 return;
22 }
23 if (element.type !== 'input' && element.type !== 'textarea' && element.type !== 'select') {
24 return;
25 }
26 if (element.props != null && element.props.value === null && !didWarnValueNull) {
27 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;
28
29 didWarnValueNull = true;
30 }
31}
32
33var ReactDOMNullInputValuePropHook = {
34 onBeforeMountComponent: function (debugID, element) {
35 handleElement(debugID, element);
36 },
37 onBeforeUpdateComponent: function (debugID, element) {
38 handleElement(debugID, element);
39 }
40};
41
42module.exports = ReactDOMNullInputValuePropHook;
\No newline at end of file