MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / createElementWithValidation

Function createElementWithValidation

code/styling/public/app.js:19581–19641  ·  view source on GitHub ↗
(type, props, children)

Source from the content-addressed store, hash-verified

19579}
19580
19581function createElementWithValidation(type, props, children) {
19582 var validType = typeof type === 'string' || typeof type === 'function' ||
19583 // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
19584 type === REACT_FRAGMENT_TYPE || type === REACT_ASYNC_MODE_TYPE || type === REACT_STRICT_MODE_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE);
19585
19586 // We warn in this case but don't throw. We expect the element creation to
19587 // succeed and there will likely be errors in render.
19588 if (!validType) {
19589 var info = '';
19590 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
19591 info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and named imports.";
19592 }
19593
19594 var sourceInfo = getSourceInfoErrorAddendum(props);
19595 if (sourceInfo) {
19596 info += sourceInfo;
19597 } else {
19598 info += getDeclarationErrorAddendum();
19599 }
19600
19601 info += getStackAddendum() || '';
19602
19603 var typeString = void 0;
19604 if (type === null) {
19605 typeString = 'null';
19606 } else if (Array.isArray(type)) {
19607 typeString = 'array';
19608 } else {
19609 typeString = typeof type;
19610 }
19611
19612 warning(false, 'React.createElement: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
19613 }
19614
19615 var element = createElement.apply(this, arguments);
19616
19617 // The result can be nullish if a mock or a custom function is used.
19618 // TODO: Drop this when these are no longer allowed as the type argument.
19619 if (element == null) {
19620 return element;
19621 }
19622
19623 // Skip key warning if the type isn't valid since our key validation logic
19624 // doesn't expect a non-string/function type and can throw confusing errors.
19625 // We don't want exception behavior to differ between dev and prod.
19626 // (Rendering will throw with a helpful message and as soon as the type is
19627 // fixed, the key warnings will appear.)
19628 if (validType) {
19629 for (var i = 2; i < arguments.length; i++) {
19630 validateChildKeys(arguments[i], type);
19631 }
19632 }
19633
19634 if (type === REACT_FRAGMENT_TYPE) {
19635 validateFragmentProps(element);
19636 } else {
19637 validatePropTypes(element);
19638 }

Callers

nothing calls this directly

Calls 7

warningFunction · 0.85
getStackAddendumFunction · 0.70
validateChildKeysFunction · 0.70
validateFragmentPropsFunction · 0.70
validatePropTypesFunction · 0.70

Tested by

no test coverage detected