|
1 | | -import { composeRef, supportRef } from 'rc-util/lib/ref'; |
2 | | -import * as React from 'react'; |
3 | 1 | import findDOMNode from 'rc-util/lib/Dom/findDOMNode'; |
4 | | -import { observe, unobserve } from '../utils/observerUtil'; |
| 2 | +import { supportRef, useComposeRef } from 'rc-util/lib/ref'; |
| 3 | +import * as React from 'react'; |
5 | 4 | import type { ResizeObserverProps } from '..'; |
6 | | -import DomWrapper from './DomWrapper'; |
7 | 5 | import { CollectionContext } from '../Collection'; |
| 6 | +import { observe, unobserve } from '../utils/observerUtil'; |
| 7 | +import DomWrapper from './DomWrapper'; |
8 | 8 |
|
9 | 9 | export interface SingleObserverProps extends ResizeObserverProps { |
10 | 10 | children: React.ReactElement | ((ref: React.RefObject<Element>) => React.ReactElement); |
@@ -34,13 +34,15 @@ function SingleObserver(props: SingleObserverProps, ref: React.Ref<HTMLElement>) |
34 | 34 | !isRenderProps && React.isValidElement(mergedChildren) && supportRef(mergedChildren); |
35 | 35 | const originRef: React.Ref<Element> = canRef ? (mergedChildren as any).ref : null; |
36 | 36 |
|
37 | | - const mergedRef = React.useMemo( |
38 | | - () => composeRef<Element>(originRef, elementRef), |
39 | | - [originRef, elementRef], |
40 | | - ); |
| 37 | + const mergedRef = useComposeRef(originRef, elementRef); |
41 | 38 |
|
42 | 39 | const getDom = () => |
43 | | - findDOMNode<HTMLElement>(elementRef.current) || findDOMNode<HTMLElement>(wrapperRef.current); |
| 40 | + findDOMNode<HTMLElement>(elementRef.current) || |
| 41 | + // Support `nativeElement` format |
| 42 | + (elementRef.current && typeof elementRef.current === 'object' |
| 43 | + ? findDOMNode<HTMLElement>((elementRef.current as any)?.nativeElement) |
| 44 | + : null) || |
| 45 | + findDOMNode<HTMLElement>(wrapperRef.current); |
44 | 46 |
|
45 | 47 | React.useImperativeHandle(ref, () => getDom()); |
46 | 48 |
|
|
0 commit comments