refactor: improve useCombinedRefs code (#27181)

* improve: useCombinedRefs code

* change location
This commit is contained in:
Tom Xu 2020-10-16 10:21:21 +08:00 committed by GitHub
parent acc2e03ddf
commit 179ee276c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 20 deletions

View File

@ -0,0 +1,19 @@
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();
React.useEffect(() => {
refs.forEach(ref => {
if (!ref) return;
fillRef(ref, targetRef.current);
});
}, [refs]);
return targetRef;
}
export default useCombinedRefs;

View File

@ -1,25 +1,6 @@
import * as React from 'react';
import Tooltip, { TooltipProps } from '../tooltip';
function useCombinedRefs(
...refs: Array<React.MutableRefObject<unknown> | ((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<unknown, TooltipProps>((props, ref) => {
const { visible } = props;