chore: Use rc-util composeRef (#27821)

This commit is contained in:
二货机器人 2020-11-17 12:01:02 +08:00 committed by GitHub
parent 696396a62f
commit 1a8bb04bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 25 deletions

View File

@ -1,19 +0,0 @@
import * as React from 'react';
import { fillRef } from '../ref';
function useCombinedRefs<T>(
...refs: Array<React.MutableRefObject<T> | ((instance: T) => void) | null>
) {
const targetRef = React.useRef<T>();
React.useEffect(() => {
refs.forEach(ref => {
if (!ref) return;
fillRef(ref, targetRef.current);
});
}, [refs]);
return targetRef;
}
export default useCombinedRefs;

View File

@ -1,13 +1,13 @@
import * as React from 'react';
import { useRef } from 'react';
import { composeRef } from 'rc-util/lib/ref';
import Tooltip, { TooltipProps } from '../tooltip';
import useCombinedRefs from '../_util/hooks/useCombinedRefs';
const SliderTooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
const { visible } = props;
const innerRef = React.useRef<any>(null);
const tooltipRef = useCombinedRefs(ref, innerRef);
const innerRef = useRef<any>(null);
const rafRef = React.useRef<number | null>(null);
const rafRef = useRef<number | null>(null);
function cancelKeepAlign() {
window.cancelAnimationFrame(rafRef.current!);
@ -16,7 +16,7 @@ const SliderTooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
function keepAlign() {
rafRef.current = window.requestAnimationFrame(() => {
(tooltipRef.current as any).forcePopupAlign();
innerRef.current.forcePopupAlign();
rafRef.current = null;
keepAlign();
});
@ -32,7 +32,7 @@ const SliderTooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {
return cancelKeepAlign;
}, [visible]);
return <Tooltip ref={tooltipRef} {...props} />;
return <Tooltip ref={composeRef(innerRef, ref)} {...props} />;
});
export default SliderTooltip;