2021-12-14 06:56:36 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
|
|
|
export const useWindowSize = () => {
|
2022-01-18 23:10:21 +00:00
|
|
|
const [size, setSize] = useState<{
|
|
|
|
width: number | undefined
|
|
|
|
height: number | undefined
|
|
|
|
}>({ width: undefined, height: undefined })
|
2021-12-14 06:56:36 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const onResize = () => {
|
|
|
|
setSize({ width: window.innerWidth, height: window.innerHeight })
|
|
|
|
}
|
|
|
|
|
2022-01-18 23:10:21 +00:00
|
|
|
onResize()
|
2021-12-14 06:56:36 +00:00
|
|
|
window.addEventListener('resize', onResize)
|
|
|
|
return () => window.removeEventListener('resize', onResize)
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
return size
|
|
|
|
}
|