mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
feat: 优化右键菜单,现在右键菜单不会超出窗口了
This commit is contained in:
30
hooks/useWindowSize.ts
Normal file
30
hooks/useWindowSize.ts
Normal 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
|
||||
Reference in New Issue
Block a user