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

Function inspectHooks

packages/react-debug-tools/src/ReactDebugHooks.js:1197–1230  ·  view source on GitHub ↗
(
  renderFunction: Props => React$Node,
  props: Props,
  currentDispatcher: ?CurrentDispatcherRef,
)

Source from the content-addressed store, hash-verified

1195}
1196
1197export function inspectHooks<Props>(
1198 renderFunction: Props => React$Node,
1199 props: Props,
1200 currentDispatcher: ?CurrentDispatcherRef,
1201): HooksTree {
1202 // DevTools will pass the current renderer's injected dispatcher.
1203 // Other apps might compile debug hooks as part of their app though.
1204 if (currentDispatcher == null) {
1205 currentDispatcher = ReactSharedInternals;
1206 }
1207
1208 const previousDispatcher = currentDispatcher.H;
1209 currentDispatcher.H = DispatcherProxy;
1210
1211 let readHookLog;
1212 let ancestorStackError;
1213
1214 try {
1215 ancestorStackError = new Error();
1216 renderFunction(props);
1217 } catch (error) {
1218 handleRenderFunctionError(error);
1219 } finally {
1220 readHookLog = hookLog;
1221 hookLog = [];
1222 // $FlowFixMe[incompatible-use] found when upgrading Flow
1223 currentDispatcher.H = previousDispatcher;
1224 }
1225 const rootStack =
1226 ancestorStackError === undefined
1227 ? ([]: ParsedStackFrame[])
1228 : ErrorStackParser.parse(ancestorStackError);
1229 return buildTree(rootStack, readHookLog);
1230}
1231
1232function setupContexts(contextMap: Map<ReactContext<any>, any>, fiber: Fiber) {
1233 let current: null | Fiber = fiber;

Callers 1

inspectHooksOfFiberFunction · 0.70

Calls 2

buildTreeFunction · 0.85

Tested by

no test coverage detected