main
js 35 lines 1.05 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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 let didWarnValueNull = false;
9
10 export function validateProperties(type, props) {
11 if (__DEV__) {
12 if (type !== 'input' && type !== 'textarea' && type !== 'select') {
13 return;
14 }
15
16 if (props != null && props.value === null && !didWarnValueNull) {
17 didWarnValueNull = true;
18 if (type === 'select' && props.multiple) {
19 console.error(
20 '`value` prop on `%s` should not be null. ' +
21 'Consider using an empty array when `multiple` is set to `true` ' +
22 'to clear the component or `undefined` for uncontrolled components.',
23 type,
24 );
25 } else {
26 console.error(
27 '`value` prop on `%s` should not be null. ' +
28 'Consider using an empty string to clear the component or `undefined` ' +
29 'for uncontrolled components.',
30 type,
31 );
32 }
33 }
34 }
35 }