@@ -3,6 +3,7 @@ import { composeRef, supportRef } from 'rc-util/lib/ref';
33import findDOMNode from 'rc-util/lib/Dom/findDOMNode' ;
44import canUseDom from 'rc-util/lib/Dom/canUseDom' ;
55import DomWrapper from './wapper' ;
6+ import useEvent from 'rc-util/es/hooks/useEvent' ;
67import type { MutationObserverProps } from './interface' ;
78
89const defOptions : MutationObserverInit = {
@@ -14,6 +15,8 @@ const defOptions: MutationObserverInit = {
1415const MutateObserver : React . FC < MutationObserverProps > = props => {
1516 const { children, options = defOptions , onMutate = ( ) => { } } = props ;
1617
18+ const callback = useEvent ( onMutate ) ;
19+
1720 const wrapperRef = useRef < DomWrapper > ( null ) ;
1821
1922 const elementRef = React . useRef < HTMLElement > ( null ) ;
@@ -34,19 +37,20 @@ const MutateObserver: React.FC<MutationObserverProps> = props => {
3437
3538 let instance : MutationObserver ;
3639
37- const currentElement = findDOMNode (
38- ( originRef as any ) ?. current || wrapperRef ?. current ,
39- ) ;
40+ const currentElement =
41+ findDOMNode ( ( originRef as any ) ?. current ) ||
42+ findDOMNode ( wrapperRef ?. current ) ;
4043
4144 if ( currentElement && 'MutationObserver' in window ) {
42- instance = new MutationObserver ( onMutate ) ;
45+ instance = new MutationObserver ( callback ) ;
4346 instance . observe ( currentElement , options ) ;
4447 }
4548 return ( ) => {
4649 instance ?. takeRecords ( ) ;
4750 instance ?. disconnect ( ) ;
4851 } ;
49- } , [ options , originRef , onMutate ] ) ;
52+ // eslint-disable-next-line react-hooks/exhaustive-deps
53+ } , [ options , originRef ] ) ;
5054
5155 if ( ! children ) {
5256 if ( process . env . NODE_ENV !== 'production' ) {
0 commit comments