Skip to content

useWindowSize

Tracks current window width and height, updating on resize.

import { useWindowSize } from 'asterui'
function WindowSizeExample() {
const { width, height } = useWindowSize()
return (
<div>
<p>Window: {width} x {height}</p>
{width < 768 && <MobileLayout />}
{width >= 768 && <DesktopLayout />}
</div>
)
}
PropertyTypeDescription
widthnumberCurrent window width in pixels
heightnumberCurrent window height in pixels

For breakpoint-based responsive logic, consider using useBreakpoint instead, which provides helper methods like isAbove() and isBelow().