From e7327bbff30b838f3b57e96271d265647ed2d6dd Mon Sep 17 00:00:00 2001 From: Wenche Tollevsen Date: Fri, 23 Oct 2020 09:40:24 +0200 Subject: [PATCH] Take two with combined refs --- .../core-react/src/_common/useCombinedRefs.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libraries/core-react/src/_common/useCombinedRefs.ts b/libraries/core-react/src/_common/useCombinedRefs.ts index 3477d28f47..bb1c5eb0fb 100644 --- a/libraries/core-react/src/_common/useCombinedRefs.ts +++ b/libraries/core-react/src/_common/useCombinedRefs.ts @@ -1,21 +1,18 @@ -// @ts-nocheck -import { useRef, useEffect, Ref } from 'react' - -export const useCombinedRefs = ( - ...refs: Array> -): Ref => { - const targetRef = useRef(null) +import { useRef, useEffect } from 'react' +type Ref = React.MutableRefObject +type useCombinedRefsProps = T | ((a: HTMLElement) => T) +export const useCombinedRefs = (...refs: useCombinedRefsProps[]): Ref => { + const targetRef = useRef(null) useEffect(() => { refs.forEach((ref) => { if (!ref) return if (typeof ref === 'function') { ref(targetRef.current) } else { - ;(ref as any).current = (targetRef as any).current + ref.current = targetRef.current } }) }, [refs]) - return targetRef }