import { useState } from 'react' ; import { useEventListener } from '../useEventListener' ; import { useMount } from '../useMount' ; export interface WindowSizeOptions { initialWidth ? : number ; initialHeight ? : number ; } param options see https export function useWindowSize ( { initialWidth = Infinity , initialHeight = Infinity } = { } ) { const [ width , setWidth ] = useState ( initialWidth ) ; const [ height , setHeight ] = useState ( initialHeight ) ; useMount ( ( ) => { setWidth ( window . innerWidth ) ; setHeight ( window . innerHeight ) ; } ) ; useEventListener ( 'resize' , ( ) => { setWidth ( window . innerWidth ) ; setHeight ( window . innerHeight ) ; } , { passive : true } ) ; return { width , height } ; }