import React from 'react' ; import useResizeObserverOriginal from 'use-resize-observer' ; import ResizeObserver from 'resize-observer-polyfill' ; if ( typeof window !== 'undefined' && ! ( window as any ) . ResizeObserver ) { ( window as any ) . ResizeObserver = ResizeObserver ; } export const useResizeObserver = ( params = { } ) => { const widthRef = React . useRef < number | undefined > ( ) ; const heightRef = React . useRef < number | undefined > ( ) ; const onResize = params . onResize ? ( data ) => { if ( widthRef . current !== data . width || heightRef . current !== data . height ) { widthRef . current = data . width ; heightRef . current = data . height ; params . onResize ! ( data ) ; } } : undefined ; return useResizeObserverOriginal ( { ... params , onResize } ) ; } ;