MCPcopy Index your code
hub / github.com/microsoft/SandDance / readContext

Function readContext

docs/external/js/react-dom.development.js:12219–12266  ·  view source on GitHub ↗
(context, observedBits)

Source from the content-addressed store, hash-verified

12217 }
12218 }
12219 function readContext(context, observedBits) {
12220 {
12221 // This warning would fire if you read context inside a Hook like useMemo.
12222 // Unlike the class check below, it's not enforced in production for perf.
12223 if (isDisallowedContextReadInDEV) {
12224 error('Context can only be read while React is rendering. ' + 'In classes, you can read it in the render method or getDerivedStateFromProps. ' + 'In function components, you can read it directly in the function body, but not ' + 'inside Hooks like useReducer() or useMemo().');
12225 }
12226 }
12227
12228 if (lastContextWithAllBitsObserved === context) ; else if (observedBits === false || observedBits === 0) ; else {
12229 var resolvedObservedBits; // Avoid deopting on observable arguments or heterogeneous types.
12230
12231 if (typeof observedBits !== 'number' || observedBits === MAX_SIGNED_31_BIT_INT) {
12232 // Observe all updates.
12233 lastContextWithAllBitsObserved = context;
12234 resolvedObservedBits = MAX_SIGNED_31_BIT_INT;
12235 } else {
12236 resolvedObservedBits = observedBits;
12237 }
12238
12239 var contextItem = {
12240 context: context,
12241 observedBits: resolvedObservedBits,
12242 next: null
12243 };
12244
12245 if (lastContextDependency === null) {
12246 if (!(currentlyRenderingFiber !== null)) {
12247 {
12248 throw Error( "Context can only be read while React is rendering. In classes, you can read it in the render method or getDerivedStateFromProps. In function components, you can read it directly in the function body, but not inside Hooks like useReducer() or useMemo()." );
12249 }
12250 } // This is the first dependency for this component. Create a new list.
12251
12252
12253 lastContextDependency = contextItem;
12254 currentlyRenderingFiber.dependencies = {
12255 expirationTime: NoWork,
12256 firstContext: contextItem,
12257 responders: null
12258 };
12259 } else {
12260 // Append a new context item.
12261 lastContextDependency = lastContextDependency.next = contextItem;
12262 }
12263 }
12264
12265 return context._currentValue ;
12266 }
12267
12268 var UpdateState = 0;
12269 var ReplaceState = 1;

Callers 6

constructClassInstanceFunction · 0.85
mountClassInstanceFunction · 0.85
resumeMountClassInstanceFunction · 0.85
updateClassInstanceFunction · 0.85
updateContextConsumerFunction · 0.85

Calls 1

errorFunction · 0.70

Tested by

no test coverage detected