-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcomponentOrElement.js
32 lines (26 loc) · 1006 Bytes
/
componentOrElement.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import React from 'react';
import createChainableTypeChecker from './utils/createChainableTypeChecker';
function validate(props, propName, componentName, location, propFullName) {
const propValue = props[propName];
const propType = typeof propValue;
if (React.isValidElement(propValue)) {
return new Error(
`Invalid ${location} \`${propFullName}\` of type ReactElement `
+ `supplied to \`${componentName}\`, expected a ReactComponent or a `
+ 'DOMElement. You can usually obtain a ReactComponent or DOMElement '
+ 'from a ReactElement by attaching a ref to it.',
);
}
if (
(propType !== 'object' || typeof propValue.render !== 'function')
&& propValue.nodeType !== 1
) {
return new Error(
`Invalid ${location} \`${propFullName}\` of value \`${propValue}\` `
+ `supplied to \`${componentName}\`, expected a ReactComponent or a `
+ 'DOMElement.',
);
}
return null;
}
export default createChainableTypeChecker(validate);