mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-25 13:12:07 +08:00
17 lines
407 B
TypeScript
17 lines
407 B
TypeScript
import { useEffect, useState } from 'react'
|
|
|
|
export const useWindowWidth = () => {
|
|
const [width, setWidth] = useState(() => document.body.clientWidth)
|
|
|
|
useEffect(() => {
|
|
const handleResize = () => setWidth(document.body.clientWidth)
|
|
|
|
window.addEventListener('resize', handleResize)
|
|
return () => {
|
|
window.removeEventListener('resize', handleResize)
|
|
}
|
|
}, [])
|
|
|
|
return { width }
|
|
}
|