feat: 优化右键菜单,现在右键菜单不会超出窗口了

This commit is contained in:
某亚瑟
2023-08-15 11:22:14 +08:00
parent 09e9f88317
commit cd4db36ab5
2 changed files with 45 additions and 3 deletions

30
hooks/useWindowSize.ts Normal file
View File

@@ -0,0 +1,30 @@
import { useEffect, useState } from 'react'
interface WindowSize {
width: number,
height: number
}
const useWindowSize = () => {
const [size, setSize] = useState<WindowSize>({
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight
})
useEffect(() => {
const onResize = () => {
setSize({
width: document.documentElement.clientWidth,
height: document.documentElement.clientHeight
})
}
onResize()
window.addEventListener('resize', onResize)
return () => {
window.removeEventListener('resize', onResize)
}
}, [])
return size
}
export default useWindowSize