File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { useEvent } from '@rc-component/util';
55
66export default function useResizeObserver (
77 enabled : boolean ,
8- getTarget : ( ) => HTMLElement ,
8+ getTarget : HTMLElement | ( ( ) => HTMLElement ) ,
99 onDelayResize ?: OnResize ,
1010 onSyncResize ?: OnResize ,
1111) {
@@ -63,8 +63,9 @@ export default function useResizeObserver(
6363 } ) ;
6464
6565 // Dynamic observe
66+ const isFuncTarget = typeof getTarget === 'function' ;
6667 React . useEffect ( ( ) => {
67- const target = getTarget ( ) ;
68+ const target = isFuncTarget ? getTarget ( ) : getTarget ;
6869
6970 if ( target && enabled ) {
7071 observe ( target , onInternalResize ) ;
@@ -75,5 +76,9 @@ export default function useResizeObserver(
7576 unobserve ( target , onInternalResize ) ;
7677 }
7778 } ;
78- } , [ enabled ] ) ;
79+ } , [
80+ enabled ,
81+ // When is function, no need to watch it
82+ isFuncTarget ? 0 : getTarget ,
83+ ] ) ;
7984}
You can’t perform that action at this time.
0 commit comments