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

Function setupContexts

packages/react-debug-tools/src/ReactDebugHooks.js:1232–1250  ·  view source on GitHub ↗
(contextMap: Map<ReactContext<any>, any>, fiber: Fiber)

Source from the content-addressed store, hash-verified

1230}
1231
1232function setupContexts(contextMap: Map<ReactContext<any>, any>, fiber: Fiber) {
1233 let current: null | Fiber = fiber;
1234 while (current) {
1235 if (current.tag === ContextProvider) {
1236 let context: ReactContext<any> = current.type;
1237 if ((context: any)._context !== undefined) {
1238 // Support inspection of pre-19+ providers.
1239 context = (context: any)._context;
1240 }
1241 if (!contextMap.has(context)) {
1242 // Store the current value that we're going to restore later.
1243 contextMap.set(context, context._currentValue);
1244 // Set the inner most provider value on the context.
1245 context._currentValue = current.memoizedProps.value;
1246 }
1247 }
1248 current = current.return;
1249 }
1250}
1251
1252function restoreContexts(contextMap: Map<ReactContext<any>, any>) {
1253 contextMap.forEach((value, context) => (context._currentValue = value));

Callers 1

inspectHooksOfFiberFunction · 0.85

Calls 2

setMethod · 0.80
hasMethod · 0.65

Tested by

no test coverage detected