MCPcopy
hub / github.com/preactjs/preact / useImperativeHandle

Function useImperativeHandle

hooks/src/index.js:314–331  ·  view source on GitHub ↗
(ref, createHandle, args)

Source from the content-addressed store, hash-verified

312 * @returns {void}
313 */
314export function useImperativeHandle(ref, createHandle, args) {
315 currentHook = 6;
316 useLayoutEffect(
317 () => {
318 if (typeof ref == 'function') {
319 const result = ref(createHandle());
320 return () => {
321 ref(null);
322 if (result && typeof result == 'function') result();
323 };
324 } else if (ref) {
325 ref.current = createHandle();
326 return () => (ref.current = null);
327 }
328 },
329 args == null ? args : args.concat(ref)
330 );
331}
332
333/**
334 * @template {unknown} T

Callers 4

CompFunction · 0.90
AppFunction · 0.90

Calls 2

useLayoutEffectFunction · 0.85
refFunction · 0.50

Tested by 2

CompFunction · 0.72
AppFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…