MCPcopy Create free account
hub / github.com/react/react / updateContextConsumer

Function updateContextConsumer

packages/react-reconciler/src/ReactFiberBeginWork.js:3634–3674  ·  view source on GitHub ↗
(
  current: Fiber | null,
  workInProgress: Fiber,
  renderLanes: Lanes,
)

Source from the content-addressed store, hash-verified

3632}
3633
3634function updateContextConsumer(
3635 current: Fiber | null,
3636 workInProgress: Fiber,
3637 renderLanes: Lanes,
3638) {
3639 const consumerType: ReactConsumerType<any> = workInProgress.type;
3640 const context: ReactContext<any> = consumerType._context;
3641 const newProps = workInProgress.pendingProps;
3642 const render = newProps.children;
3643
3644 if (__DEV__) {
3645 if (typeof render !== 'function') {
3646 console.error(
3647 'A context consumer was rendered with multiple children, or a child ' +
3648 "that isn't a function. A context consumer expects a single child " +
3649 'that is a function. If you did pass a function, make sure there ' +
3650 'is no trailing or leading whitespace around it.',
3651 );
3652 }
3653 }
3654
3655 prepareToReadContext(workInProgress, renderLanes);
3656 const newValue = readContext(context);
3657 if (enableSchedulingProfiler) {
3658 markComponentRenderStarted(workInProgress);
3659 }
3660 let newChildren;
3661 if (__DEV__) {
3662 newChildren = callComponentInDEV(render, newValue, undefined);
3663 } else {
3664 newChildren = render(newValue);
3665 }
3666 if (enableSchedulingProfiler) {
3667 markComponentRenderStopped();
3668 }
3669
3670 // React DevTools reads this flag.
3671 workInProgress.flags |= PerformedWork;
3672 reconcileChildren(current, workInProgress, newChildren, renderLanes);
3673 return workInProgress.child;
3674}
3675
3676function updateScopeComponent(
3677 current: null | Fiber,

Callers 1

beginWorkFunction · 0.85

Calls 7

prepareToReadContextFunction · 0.90
readContextFunction · 0.90
reconcileChildrenFunction · 0.85
errorMethod · 0.65
renderFunction · 0.50

Tested by

no test coverage detected