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

Function createElementWithValidation

code/third-party/public/app.js:18814–18874  ·  view source on GitHub ↗
(type, props, children)

Source from the content-addressed store, hash-verified

18812}
18813
18814function createElementWithValidation(type, props, children) {
18815 var validType = typeof type === 'string' || typeof type === 'function' ||
18816 // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
18817 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);
18818
18819 // We warn in this case but don't throw. We expect the element creation to
18820 // succeed and there will likely be errors in render.
18821 if (!validType) {
18822 var info = '';
18823 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
18824 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.";
18825 }
18826
18827 var sourceInfo = getSourceInfoErrorAddendum(props);
18828 if (sourceInfo) {
18829 info += sourceInfo;
18830 } else {
18831 info += getDeclarationErrorAddendum();
18832 }
18833
18834 info += getStackAddendum() || '';
18835
18836 var typeString = void 0;
18837 if (type === null) {
18838 typeString = 'null';
18839 } else if (Array.isArray(type)) {
18840 typeString = 'array';
18841 } else {
18842 typeString = typeof type;
18843 }
18844
18845 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);
18846 }
18847
18848 var element = createElement.apply(this, arguments);
18849
18850 // The result can be nullish if a mock or a custom function is used.
18851 // TODO: Drop this when these are no longer allowed as the type argument.
18852 if (element == null) {
18853 return element;
18854 }
18855
18856 // Skip key warning if the type isn't valid since our key validation logic
18857 // doesn't expect a non-string/function type and can throw confusing errors.
18858 // We don't want exception behavior to differ between dev and prod.
18859 // (Rendering will throw with a helpful message and as soon as the type is
18860 // fixed, the key warnings will appear.)
18861 if (validType) {
18862 for (var i = 2; i < arguments.length; i++) {
18863 validateChildKeys(arguments[i], type);
18864 }
18865 }
18866
18867 if (type === REACT_FRAGMENT_TYPE) {
18868 validateFragmentProps(element);
18869 } else {
18870 validatePropTypes(element);
18871 }

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