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

Function updateMemoComponent

packages/react-reconciler/src/ReactFiberBeginWork.js:472–538  ·  view source on GitHub ↗
(
  current: Fiber | null,
  workInProgress: Fiber,
  Component: any,
  nextProps: any,
  renderLanes: Lanes,
)

Source from the content-addressed store, hash-verified

470}
471
472function updateMemoComponent(
473 current: Fiber | null,
474 workInProgress: Fiber,
475 Component: any,
476 nextProps: any,
477 renderLanes: Lanes,
478): null | Fiber {
479 if (current === null) {
480 const type = Component.type;
481 if (isSimpleFunctionComponent(type) && Component.compare === null) {
482 let resolvedType = type;
483 if (__DEV__) {
484 resolvedType = resolveFunctionForHotReloading(type);
485 }
486 // If this is a plain function component without default props,
487 // and with only the default shallow comparison, we upgrade it
488 // to a SimpleMemoComponent to allow fast path updates.
489 workInProgress.tag = SimpleMemoComponent;
490 workInProgress.type = resolvedType;
491 if (__DEV__) {
492 validateFunctionComponentInDev(workInProgress, type);
493 }
494 return updateSimpleMemoComponent(
495 current,
496 workInProgress,
497 resolvedType,
498 nextProps,
499 renderLanes,
500 );
501 }
502 const child = createFiberFromTypeAndProps(
503 Component.type,
504 null,
505 nextProps,
506 workInProgress,
507 workInProgress.mode,
508 renderLanes,
509 );
510 child.ref = workInProgress.ref;
511 child.return = workInProgress;
512 workInProgress.child = child;
513 return child;
514 }
515 const currentChild = ((current.child: any): Fiber); // This is always exactly one child
516 const hasScheduledUpdateOrContext = checkScheduledUpdateOrContext(
517 current,
518 renderLanes,
519 );
520 if (!hasScheduledUpdateOrContext) {
521 // This will be the props with resolved defaultProps,
522 // unlike current.memoizedProps which will be the unresolved ones.
523 const prevProps = currentChild.memoizedProps;
524 // Default to shallow comparison
525 let compare = Component.compare;
526 compare = compare !== null ? compare : shallowEqual;
527 if (compare(prevProps, nextProps) && current.ref === workInProgress.ref) {
528 return bailoutOnAlreadyFinishedWork(current, workInProgress, renderLanes);
529 }

Callers 2

mountLazyComponentFunction · 0.85
beginWorkFunction · 0.85

Calls 9

createWorkInProgressFunction · 0.90
compareFunction · 0.85

Tested by

no test coverage detected