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

Function jsxDEVImpl

packages/react/src/jsx/ReactJSXElement.js:427–554  ·  view source on GitHub ↗
(
  type,
  config,
  maybeKey,
  isStaticChildren,
  debugStack,
  debugTask,
)

Source from the content-addressed store, hash-verified

425}
426
427function jsxDEVImpl(
428 type,
429 config,
430 maybeKey,
431 isStaticChildren,
432 debugStack,
433 debugTask,
434) {
435 if (__DEV__) {
436 // We don't warn for invalid element type here because with owner stacks,
437 // we error in the renderer. The renderer is the only one that knows what
438 // types are valid for this particular renderer so we let it error there.
439
440 // Skip key warning if the type isn't valid since our key validation logic
441 // doesn't expect a non-string/function type and can throw confusing
442 // errors. We don't want exception behavior to differ between dev and
443 // prod. (Rendering will throw with a helpful message and as soon as the
444 // type is fixed, the key warnings will appear.)
445 // With owner stacks, we no longer need the type here so this comment is
446 // no longer true. Which is why we can run this even for invalid types.
447 const children = config.children;
448 if (children !== undefined) {
449 if (isStaticChildren) {
450 if (isArray(children)) {
451 for (let i = 0; i < children.length; i++) {
452 validateChildKeys(children[i]);
453 }
454
455 if (Object.freeze) {
456 Object.freeze(children);
457 }
458 } else {
459 console.error(
460 'React.jsx: Static children should always be an array. ' +
461 'You are likely explicitly calling React.jsxs or React.jsxDEV. ' +
462 'Use the Babel transform instead.',
463 );
464 }
465 } else {
466 validateChildKeys(children);
467 }
468 }
469
470 // Warn about key spread regardless of whether the type is valid.
471 if (hasOwnProperty.call(config, 'key')) {
472 const componentName = getComponentNameFromType(type);
473 const keys = Object.keys(config).filter(k => k !== 'key');
474 const beforeExample =
475 keys.length > 0
476 ? '{key: someKey, ' + keys.join(': ..., ') + ': ...}'
477 : '{key: someKey}';
478 if (!didWarnAboutKeySpread[componentName + beforeExample]) {
479 const afterExample =
480 keys.length > 0 ? '{' + keys.join(': ..., ') + ': ...}' : '{}';
481 console.error(
482 'A props object containing a "key" prop is being spread into JSX:\n' +
483 ' let props = %s;\n' +
484 ' <%s {...props} />\n' +

Calls 12

checkKeyStringCoercionFunction · 0.90
isArrayFunction · 0.85
getComponentNameFromTypeFunction · 0.85
freezeMethod · 0.80
keysMethod · 0.80
joinMethod · 0.80
validateChildKeysFunction · 0.70
hasValidKeyFunction · 0.70
ReactElementFunction · 0.70
getOwnerFunction · 0.70
errorMethod · 0.65

Tested by

no test coverage detected