File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -64,11 +64,15 @@ export default function useResizeObserver(
6464
6565 // Dynamic observe
6666 const isFuncTarget = typeof getTarget === 'function' ;
67+ const funcTargetIdRef = React . useRef ( 0 ) ;
68+
6769 React . useEffect ( ( ) => {
6870 const target = isFuncTarget ? getTarget ( ) : getTarget ;
6971
7072 if ( target && enabled ) {
7173 observe ( target , onInternalResize ) ;
74+ } else if ( enabled && isFuncTarget ) {
75+ funcTargetIdRef . current += 1 ;
7276 }
7377
7478 return ( ) => {
@@ -78,7 +82,8 @@ export default function useResizeObserver(
7882 } ;
7983 } , [
8084 enabled ,
81- // When is function, no need to watch it
82- isFuncTarget ? 0 : getTarget ,
85+ // If function target resolves after a parent render, the bumped ref value
86+ // lets the next render re-run this effect without watching the function identity.
87+ isFuncTarget ? funcTargetIdRef . current : getTarget ,
8388 ] ) ;
8489}
You can’t perform that action at this time.
0 commit comments