MCPcopy
hub / github.com/react/react / getMaskedContext

Function getMaskedContext

packages/react-reconciler/src/ReactFiberLegacyContext.js:73–110  ·  view source on GitHub ↗
(
  workInProgress: Fiber,
  unmaskedContext: Object,
)

Source from the content-addressed store, hash-verified

71}
72
73function getMaskedContext(
74 workInProgress: Fiber,
75 unmaskedContext: Object,
76): Object {
77 if (disableLegacyContext) {
78 return emptyContextObject;
79 } else {
80 const type = workInProgress.type;
81 const contextTypes = type.contextTypes;
82 if (!contextTypes) {
83 return emptyContextObject;
84 }
85
86 // Avoid recreating masked context unless unmasked context has changed.
87 // Failing to do this will result in unnecessary calls to componentWillReceiveProps.
88 // This may trigger infinite loops if componentWillReceiveProps calls setState.
89 const instance = workInProgress.stateNode;
90 if (
91 instance &&
92 instance.__reactInternalMemoizedUnmaskedChildContext === unmaskedContext
93 ) {
94 return instance.__reactInternalMemoizedMaskedChildContext;
95 }
96
97 const context: {[string]: $FlowFixMe} = {};
98 for (const key in contextTypes) {
99 context[key] = unmaskedContext[key];
100 }
101
102 // Cache unmasked context so we can avoid recreating masked context unless necessary.
103 // Context is created before the class component is instantiated so check for instance.
104 if (instance) {
105 cacheContext(workInProgress, unmaskedContext, context);
106 }
107
108 return context;
109 }
110}
111
112function hasContextChanged(): boolean {
113 if (disableLegacyContext) {

Callers 6

updateFunctionComponentFunction · 0.90
replayBeginWorkFunction · 0.90
constructClassInstanceFunction · 0.90
mountClassInstanceFunction · 0.90
resumeMountClassInstanceFunction · 0.90
updateClassInstanceFunction · 0.90

Calls 1

cacheContextFunction · 0.85

Tested by

no test coverage detected