UNPKG

1.14 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4
5function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
6
7var _react = require('react');
8
9var _react2 = _interopRequireDefault(_react);
10
11var _common = require('./common');
12
13/**
14 * Checks whether a prop provides a type of element.
15 *
16 * The type of element can be provided in two forms:
17 * - tag name (string)
18 * - a return value of React.createClass(...)
19 *
20 * @param props
21 * @param propName
22 * @param componentName
23 * @returns {Error|undefined}
24 */
25
26function validate(props, propName, componentName) {
27 var errBeginning = _common.errMsg(props, propName, componentName, '. Expected an Element `type`');
28
29 if (typeof props[propName] !== 'function') {
30 if (_react2['default'].isValidElement(props[propName])) {
31 return new Error(errBeginning + ', not an actual Element');
32 }
33
34 if (typeof props[propName] !== 'string') {
35 return new Error(errBeginning + ' such as a tag name or return value of React.createClass(...)');
36 }
37 }
38}
39
40exports['default'] = _common.createChainableTypeChecker(validate);
41module.exports = exports['default'];
\No newline at end of file