mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
force graph, palette
This commit is contained in:
28
web/lib/utils/window-size.ts
Normal file
28
web/lib/utils/window-size.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user