1- import findDOMNode from 'rc-util/lib/Dom/findDOMNode' ;
2- import { supportRef , useComposeRef , getNodeRef } from 'rc-util/lib/ref' ;
1+ import { getDOM } from '@ rc-component/ util/lib/Dom/findDOMNode' ;
2+ import { supportRef , useComposeRef , getNodeRef } from '@ rc-component/ util/lib/ref' ;
33import * as React from 'react' ;
44import type { ResizeObserverProps } from '..' ;
55import { CollectionContext } from '../Collection' ;
66import { observe , unobserve } from '../utils/observerUtil' ;
7- import DomWrapper from './DomWrapper' ;
87
98export interface SingleObserverProps extends ResizeObserverProps {
109 children : React . ReactElement | ( ( ref : React . RefObject < Element > ) => React . ReactElement ) ;
@@ -13,7 +12,6 @@ export interface SingleObserverProps extends ResizeObserverProps {
1312function SingleObserver ( props : SingleObserverProps , ref : React . Ref < HTMLElement > ) {
1413 const { children, disabled } = props ;
1514 const elementRef = React . useRef < Element > ( null ) ;
16- const wrapperRef = React . useRef < DomWrapper > ( null ) ;
1715
1816 const onCollectionResize = React . useContext ( CollectionContext ) ;
1917
@@ -36,15 +34,12 @@ function SingleObserver(props: SingleObserverProps, ref: React.Ref<HTMLElement>)
3634
3735 const mergedRef = useComposeRef ( originRef , elementRef ) ;
3836
39- const getDom = ( ) =>
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 ) ;
37+ const getDomElement = ( ) => {
38+ return getDOM ( elementRef . current ) as HTMLElement
39+ }
40+
4641
47- React . useImperativeHandle ( ref , ( ) => getDom ( ) ) ;
42+ React . useImperativeHandle ( ref , ( ) => getDomElement ( ) ) ;
4843
4944 // =========================== Observe ============================
5045 const propsRef = React . useRef < SingleObserverProps > ( props ) ;
@@ -98,7 +93,7 @@ function SingleObserver(props: SingleObserverProps, ref: React.Ref<HTMLElement>)
9893
9994 // Dynamic observe
10095 React . useEffect ( ( ) => {
101- const currentElement : HTMLElement = getDom ( ) ;
96+ const currentElement : HTMLElement = getDomElement ( ) ;
10297
10398 if ( currentElement && ! disabled ) {
10499 observe ( currentElement , onInternalResize ) ;
@@ -109,13 +104,11 @@ function SingleObserver(props: SingleObserverProps, ref: React.Ref<HTMLElement>)
109104
110105 // ============================ Render ============================
111106 return (
112- < DomWrapper ref = { wrapperRef } >
113- { canRef
107+ canRef
114108 ? React . cloneElement ( mergedChildren as any , {
115109 ref : mergedRef ,
116110 } )
117- : mergedChildren }
118- </ DomWrapper >
111+ : mergedChildren
119112 ) ;
120113}
121114
0 commit comments