MCPcopy
hub / github.com/facebook/react / createElement

Function createElement

packages/react/src/jsx/ReactJSXElement.js:560–684  ·  view source on GitHub ↗
(type, config, children)

Source from the content-addressed store, hash-verified

558 * See https://reactjs.org/docs/react-api.html#createelement
559 */
560export function createElement(type, config, children) {
561 if (__DEV__) {
562 // We don't warn for invalid element type here because with owner stacks,
563 // we error in the renderer. The renderer is the only one that knows what
564 // types are valid for this particular renderer so we let it error there.
565
566 // Skip key warning if the type isn't valid since our key validation logic
567 // doesn't expect a non-string/function type and can throw confusing
568 // errors. We don't want exception behavior to differ between dev and
569 // prod. (Rendering will throw with a helpful message and as soon as the
570 // type is fixed, the key warnings will appear.)
571 for (let i = 2; i < arguments.length; i++) {
572 validateChildKeys(arguments[i]);
573 }
574
575 // Unlike the jsx() runtime, createElement() doesn't warn about key spread.
576 }
577
578 let propName;
579
580 // Reserved names are extracted
581 const props = {};
582
583 let key = null;
584
585 if (config != null) {
586 if (__DEV__) {
587 if (
588 !didWarnAboutOldJSXRuntime &&
589 '__self' in config &&
590 // Do not assume this is the result of an oudated JSX transform if key
591 // is present, because the modern JSX transform sometimes outputs
592 // createElement to preserve precedence between a static key and a
593 // spread key. To avoid false positive warnings, we never warn if
594 // there's a key.
595 !('key' in config)
596 ) {
597 didWarnAboutOldJSXRuntime = true;
598 console.warn(
599 'Your app (or one of its dependencies) is using an outdated JSX ' +
600 'transform. Update to the modern JSX transform for ' +
601 'faster performance: https://react.dev/link/new-jsx-transform',
602 );
603 }
604 }
605
606 if (hasValidKey(config)) {
607 if (__DEV__) {
608 checkKeyStringCoercion(config.key);
609 }
610 key = '' + config.key;
611 }
612
613 // Remaining properties are added to a new props object
614 for (propName in config) {
615 if (
616 hasOwnProperty.call(config, propName) &&
617 // Skip over reserved prop names

Callers 9

reloadFunction · 0.90
mountAppFunction · 0.90
StrictRootFunction · 0.90
mountStrictAppFunction · 0.90
LegacyRenderFunction · 0.90
mountLegacyAppFunction · 0.90
connectFunction · 0.90
utils-test.jsFile · 0.90
createBridgeAndStoreFunction · 0.90

Calls 9

checkKeyStringCoercionFunction · 0.90
createTaskFunction · 0.85
getTaskNameFunction · 0.85
freezeMethod · 0.80
validateChildKeysFunction · 0.70
hasValidKeyFunction · 0.70
ReactElementFunction · 0.70
getOwnerFunction · 0.70

Tested by

no test coverage detected