mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
29 lines
628 B
TypeScript
29 lines
628 B
TypeScript
import * as react from "react"
|
|
|
|
export type WindowSize = {
|
|
width: number,
|
|
height: number,
|
|
}
|
|
|
|
export function getWindowSize(): WindowSize {
|
|
return {
|
|
width: window.innerWidth,
|
|
height: window.innerHeight,
|
|
}
|
|
}
|
|
|
|
export function useWindowSize(): WindowSize {
|
|
|
|
let [window_size, setWindowSize] = react.useState(getWindowSize())
|
|
|
|
react.useEffect(() => {
|
|
function handleResize() {
|
|
setWindowSize(getWindowSize())
|
|
}
|
|
window.addEventListener("resize", handleResize)
|
|
return () => window.removeEventListener("resize", handleResize)
|
|
}, [])
|
|
|
|
return window_size
|
|
}
|