From fa6479e26da232d5a4cca8b035f48b15a614e74b Mon Sep 17 00:00:00 2001 From: Dmitri Date: Thu, 12 Dec 2024 20:37:13 +0200 Subject: [PATCH] Avoid error in logs on React <19 when using composeRefs --- .../react/compose-refs/src/composeRefs.tsx | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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); + } + }); + }; + } }; }