MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / composedRefCallback

Function composedRefCallback

packages/react/src/lib/compose-refs.ts:11–26  ·  view source on GitHub ↗
(outer: React.Ref<T> | undefined, local: React.RefObject<T | null>)

Source from the content-addressed store, hash-verified

9 */
10export const composedRefCallback =
11 <T>(outer: React.Ref<T> | undefined, local: React.RefObject<T | null>): React.RefCallback<T> =>
12 (node) => {
13 local.current = node;
14 if (typeof outer === "function") {
15 const cleanup = outer(node);
16 if (typeof cleanup === "function") {
17 return () => {
18 local.current = null;
19 cleanup();
20 };
21 }
22 return undefined;
23 }
24 if (outer) outer.current = node;
25 return undefined;
26 };
27
28/** `composedRefCallback`, kept stable across renders for stable inputs so the
29 * incoming ref is not detached and reattached on every render. */

Callers 2

useComposedRefFunction · 0.85

Calls 1

cleanupFunction · 0.50

Tested by

no test coverage detected