diff --git a/packages/react/compose-refs/src/composeRefs.tsx b/packages/react/compose-refs/src/composeRefs.tsx index 120af58d8..f943c62d1 100644 --- a/packages/react/compose-refs/src/composeRefs.tsx +++ b/packages/react/compose-refs/src/composeRefs.tsx @@ -21,15 +21,17 @@ function setRef(ref: PossibleRef, value: T) { function composeRefs(...refs: PossibleRef[]) { return (node: T) => { const cleanups = refs.map((ref) => setRef(ref, node)); - return () => { - cleanups.forEach((cleanup, i) => { - if (typeof cleanup == 'function') { - cleanup(); - } else { - setRef(refs[i], null); - } - }); - }; + if (cleanups.some((c) => typeof c == 'function')) { + return () => { + cleanups.forEach((cleanup, i) => { + if (typeof cleanup == 'function') { + cleanup(); + } else { + setRef(refs[i], null); + } + }); + }; + } }; }