diff --git a/components/_util/hooks/useCombinedRefs.tsx b/components/_util/hooks/useCombinedRefs.tsx new file mode 100644 index 0000000000..d1ea07de2e --- /dev/null +++ b/components/_util/hooks/useCombinedRefs.tsx @@ -0,0 +1,19 @@ +import * as React from 'react'; +import { fillRef } from '../ref'; + +function useCombinedRefs( + ...refs: Array | ((instance: T) => void) | null> +) { + const targetRef = React.useRef(); + + React.useEffect(() => { + refs.forEach(ref => { + if (!ref) return; + fillRef(ref, targetRef.current); + }); + }, [refs]); + + return targetRef; +} + +export default useCombinedRefs; diff --git a/components/slider/SliderTooltip.tsx b/components/slider/SliderTooltip.tsx index 4a5fda46a8..3f806ff78a 100644 --- a/components/slider/SliderTooltip.tsx +++ b/components/slider/SliderTooltip.tsx @@ -1,25 +1,6 @@ import * as React from 'react'; import Tooltip, { TooltipProps } from '../tooltip'; - -function useCombinedRefs( - ...refs: Array | ((instance: unknown) => void) | null> -) { - const targetRef = React.useRef(); - - React.useEffect(() => { - refs.forEach(ref => { - if (!ref) return; - - if (typeof ref === 'function') { - ref(targetRef.current); - } else { - ref.current = targetRef.current; - } - }); - }, [refs]); - - return targetRef; -} +import useCombinedRefs from '../_util/hooks/useCombinedRefs'; const SliderTooltip = React.forwardRef((props, ref) => { const { visible } = props;