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

Function createElementWithValidation

code/composition/public/app.js:19719–19779  ·  view source on GitHub ↗
(type, props, children)

Source from the content-addressed store, hash-verified

19717}
19718
19719function createElementWithValidation(type, props, children) {
19720 var validType = typeof type === 'string' || typeof type === 'function' ||
19721 // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
19722 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);
19723
19724 // We warn in this case but don't throw. We expect the element creation to
19725 // succeed and there will likely be errors in render.
19726 if (!validType) {
19727 var info = '';
19728 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
19729 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.";
19730 }
19731
19732 var sourceInfo = getSourceInfoErrorAddendum(props);
19733 if (sourceInfo) {
19734 info += sourceInfo;
19735 } else {
19736 info += getDeclarationErrorAddendum();
19737 }
19738
19739 info += getStackAddendum() || '';
19740
19741 var typeString = void 0;
19742 if (type === null) {
19743 typeString = 'null';
19744 } else if (Array.isArray(type)) {
19745 typeString = 'array';
19746 } else {
19747 typeString = typeof type;
19748 }
19749
19750 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);
19751 }
19752
19753 var element = createElement.apply(this, arguments);
19754
19755 // The result can be nullish if a mock or a custom function is used.
19756 // TODO: Drop this when these are no longer allowed as the type argument.
19757 if (element == null) {
19758 return element;
19759 }
19760
19761 // Skip key warning if the type isn't valid since our key validation logic
19762 // doesn't expect a non-string/function type and can throw confusing errors.
19763 // We don't want exception behavior to differ between dev and prod.
19764 // (Rendering will throw with a helpful message and as soon as the type is
19765 // fixed, the key warnings will appear.)
19766 if (validType) {
19767 for (var i = 2; i < arguments.length; i++) {
19768 validateChildKeys(arguments[i], type);
19769 }
19770 }
19771
19772 if (type === REACT_FRAGMENT_TYPE) {
19773 validateFragmentProps(element);
19774 } else {
19775 validatePropTypes(element);
19776 }

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