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

Function useImperativeHandle

packages/react-debug-tools/src/ReactDebugHooks.js:397–419  ·  view source on GitHub ↗
(
  ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
  create: () => T,
  inputs: Array<mixed> | void | null,
)

Source from the content-addressed store, hash-verified

395}
396
397function useImperativeHandle<T>(
398 ref: {current: T | null} | ((inst: T | null) => mixed) | null | void,
399 create: () => T,
400 inputs: Array<mixed> | void | null,
401): void {
402 nextHook();
403 // We don't actually store the instance anywhere if there is no ref callback
404 // and if there is a ref callback it might not store it but if it does we
405 // have no way of knowing where. So let's only enable introspection of the
406 // ref itself if it is using the object form.
407 let instance: ?T = undefined;
408 if (ref !== null && typeof ref === 'object') {
409 instance = ref.current;
410 }
411 hookLog.push({
412 displayName: null,
413 primitive: 'ImperativeHandle',
414 stackError: new Error(),
415 value: instance,
416 debugInfo: null,
417 dispatcherHookName: 'ImperativeHandle',
418 });
419}
420
421function useDebugValue(value: any, formatterFn: ?(value: any) => any) {
422 hookLog.push({

Callers 2

ContextMenuContainerFunction · 0.90
CounterFunction · 0.50

Calls 2

nextHookFunction · 0.85
pushMethod · 0.65

Tested by 1

CounterFunction · 0.40