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

Function placeChild

packages/react-reconciler/src/ReactChildFiber.js:492–520  ·  view source on GitHub ↗
(
    newFiber: Fiber,
    lastPlacedIndex: number,
    newIndex: number,
  )

Source from the content-addressed store, hash-verified

490 }
491
492 function placeChild(
493 newFiber: Fiber,
494 lastPlacedIndex: number,
495 newIndex: number,
496 ): number {
497 newFiber.index = newIndex;
498 if (!shouldTrackSideEffects) {
499 // During hydration, the useId algorithm needs to know which fibers are
500 // part of a list of children (arrays, iterators).
501 newFiber.flags |= Forked;
502 return lastPlacedIndex;
503 }
504 const current = newFiber.alternate;
505 if (current !== null) {
506 const oldIndex = current.index;
507 if (oldIndex < lastPlacedIndex) {
508 // This is a move.
509 newFiber.flags |= Placement | PlacementDEV;
510 return lastPlacedIndex;
511 } else {
512 // This item can stay in place.
513 return oldIndex;
514 }
515 } else {
516 // This is an insertion.
517 newFiber.flags |= Placement | PlacementDEV;
518 return lastPlacedIndex;
519 }
520 }
521
522 function placeSingleChild(newFiber: Fiber): Fiber {
523 // This is simpler for the single child case. We only need to do a

Callers 2

reconcileChildrenArrayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected