MCPcopy Index your code
hub / github.com/react/react / createChild

Function createChild

packages/react-reconciler/src/ReactChildFiber.js:681–809  ·  view source on GitHub ↗
(
    returnFiber: Fiber,
    newChild: any,
    lanes: Lanes,
  )

Source from the content-addressed store, hash-verified

679 }
680
681 function createChild(
682 returnFiber: Fiber,
683 newChild: any,
684 lanes: Lanes,
685 ): Fiber | null {
686 if (
687 (typeof newChild === 'string' && newChild !== '') ||
688 typeof newChild === 'number' ||
689 typeof newChild === 'bigint'
690 ) {
691 // Text nodes don't have keys. If the previous node is implicitly keyed
692 // we can continue to replace it without aborting even if it is not a text
693 // node.
694 const created = createFiberFromText(
695 // $FlowFixMe[unsafe-addition] Flow doesn't want us to use `+` operator with string and bigint
696 '' + newChild,
697 returnFiber.mode,
698 lanes,
699 );
700 created.return = returnFiber;
701 if (__DEV__) {
702 // We treat the parent as the owner for stack purposes.
703 created._debugOwner = returnFiber;
704 created._debugTask = returnFiber._debugTask;
705 created._debugInfo = currentDebugInfo;
706 }
707 return created;
708 }
709
710 if (typeof newChild === 'object' && newChild !== null) {
711 switch (newChild.$$typeof) {
712 case REACT_ELEMENT_TYPE: {
713 const created = createFiberFromElement(
714 newChild,
715 returnFiber.mode,
716 lanes,
717 );
718 coerceRef(created, newChild);
719 created.return = returnFiber;
720 if (__DEV__) {
721 const prevDebugInfo = pushDebugInfo(newChild._debugInfo);
722 created._debugInfo = currentDebugInfo;
723 currentDebugInfo = prevDebugInfo;
724 }
725 return created;
726 }
727 case REACT_PORTAL_TYPE: {
728 const created = createFiberFromPortal(
729 newChild,
730 returnFiber.mode,
731 lanes,
732 );
733 created.return = returnFiber;
734 if (__DEV__) {
735 created._debugInfo = currentDebugInfo;
736 }
737 return created;
738 }

Callers 2

reconcileChildrenArrayFunction · 0.85

Calls 14

createFiberFromTextFunction · 0.90
createFiberFromElementFunction · 0.90
createFiberFromPortalFunction · 0.90
resolveLazyFunction · 0.90
createFiberFromFragmentFunction · 0.90
coerceRefFunction · 0.85
pushDebugInfoFunction · 0.85
isArrayFunction · 0.85
throwOnInvalidObjectTypeFunction · 0.85
unwrapThenableFunction · 0.70
warnOnFunctionTypeFunction · 0.70

Tested by

no test coverage detected