import { useEffect , useRef } from "react" ; param onResize export function useWindowResize ( onResize ) { const resizeRef = useRef < ( ) => void > ( onResize ) ; resizeRef . current = onResize ; useEffect ( ( ) => { const callback = ( ) => resizeRef . current ( ) ; window . addEventListener ( "resize" , callback ) ; if ( window . onorientationchange !== undefined ) { window . addEventListener ( "orientationchange" , callback ) ; } return ( ) => { window . removeEventListener ( "resize" , callback ) ; if ( window . onorientationchange !== undefined ) { window . removeEventListener ( "orientationchange" , callback ) ; } } ; } , [ ] ) ; }