@radix-ui/react-compose-refs
Advanced tools
Comparing version 1.1.1-rc.2 to 1.1.1-rc.3
@@ -8,3 +8,3 @@ import * as React from 'react'; | ||
*/ | ||
declare function composeRefs<T>(...refs: PossibleRef<T>[]): (node: T) => (() => void) | undefined; | ||
declare function composeRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T>; | ||
/** | ||
@@ -14,4 +14,4 @@ * A custom hook that composes multiple refs | ||
*/ | ||
declare function useComposedRefs<T>(...refs: PossibleRef<T>[]): (node: T) => (() => void) | undefined; | ||
declare function useComposedRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T>; | ||
export { composeRefs, useComposedRefs }; |
@@ -49,6 +49,14 @@ "use strict"; | ||
return (node) => { | ||
const cleanups = refs.map((ref) => setRef(ref, node)); | ||
if (cleanups.some((c) => typeof c == "function")) { | ||
let hasCleanup = false; | ||
const cleanups = refs.map((ref) => { | ||
const cleanup = setRef(ref, node); | ||
if (!hasCleanup && typeof cleanup == "function") { | ||
hasCleanup = true; | ||
} | ||
return cleanup; | ||
}); | ||
if (hasCleanup) { | ||
return () => { | ||
cleanups.forEach((cleanup, i) => { | ||
for (let i = 0; i < cleanups.length; i++) { | ||
const cleanup = cleanups[i]; | ||
if (typeof cleanup == "function") { | ||
@@ -59,3 +67,3 @@ cleanup(); | ||
} | ||
}); | ||
} | ||
}; | ||
@@ -62,0 +70,0 @@ } |
{ | ||
"name": "@radix-ui/react-compose-refs", | ||
"version": "1.1.1-rc.2", | ||
"version": "1.1.1-rc.3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "exports": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
11193
126