manifold/web/hooks/use-window-size.ts
2022-01-18 17:10:21 -06:00

21 lines
508 B
TypeScript

import { useEffect, useState } from 'react'
export const useWindowSize = () => {
const [size, setSize] = useState<{
width: number | undefined
height: number | undefined
}>({ width: undefined, height: undefined })
useEffect(() => {
const onResize = () => {
setSize({ width: window.innerWidth, height: window.innerHeight })
}
onResize()
window.addEventListener('resize', onResize)
return () => window.removeEventListener('resize', onResize)
}, [])
return size
}