File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed
src/components/common/helpers Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -1114,26 +1114,21 @@ export const reloadToastBody = () => {
1114
1114
1115
1115
export function useHeightObserver ( callback ) : [ RefObject < HTMLDivElement > ] {
1116
1116
const ref = useRef ( null )
1117
- const callbackRef = useRef ( callback )
1118
1117
1119
- useLayoutEffect ( ( ) => {
1120
- callbackRef . current = callback
1121
- } , [ callback ] )
1122
-
1123
- const handleHeightChange = useCallback ( ( ) => {
1124
- callbackRef . current ?.( ref . current . clientHeight )
1125
- } , [ callbackRef ] )
1126
-
1127
- useLayoutEffect ( ( ) => {
1118
+ useEffect ( ( ) => {
1128
1119
if ( ! ref . current ) {
1129
1120
return
1130
1121
}
1131
- const observer = new ResizeObserver ( handleHeightChange )
1122
+ const observer = new ResizeObserver ( ( ) => {
1123
+ /* this will prevent infinite loop */
1124
+ /* the callback will be called only before the next repaint */
1125
+ window . requestAnimationFrame ( callback )
1126
+ } )
1132
1127
observer . observe ( ref . current )
1133
1128
return ( ) => {
1134
1129
observer . disconnect ( )
1135
1130
}
1136
- } , [ handleHeightChange , ref ] )
1131
+ } , [ callback ] )
1137
1132
1138
1133
return [ ref ]
1139
1134
}
You can’t perform that action at this time.
0 commit comments