Size
0.43 kb
useWindowSize
Track the dimensions of the window.
Features
- Optimized performance: Leverages a shared listener pool to reduce event subscriptions.
- Custom state tracking: disable internal state tracking with
trackState
. - Event-driven updates: Provides an
onChange
callback for reacting to dimension changes.
Installation
Usage
Setting ssr
to true
initializes width and height as undefined
to prevent hydration mismatches between server and client.
Use trackState: false
to disable state tracking, the onChange
callback is executed whenever the window size changes.
API Reference
DefineUseWindowSizeOptions
Options for the `defineUseWindowSize` hook.
Prop | Type | Default |
---|---|---|
ssr? | TSSR | - |
UseWindowSizeOptions
Options for the `useWindowSize` hook.
Prop | Type | Default |
---|---|---|
onChange? | ((size: { width: number; height: number; }) => void) | - |
trackState? | boolean | true |
UseWindowSizeReturn
The return value of the `useWindowSize` hook.
Prop | Type | Default |
---|---|---|
height? | number | - |
width? | number | - |