Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rijvi-mahmud/shaddy/llms.txt
Use this file to discover all available pages before exploring further.
useWindowResize is a React hook that returns the current width and height of the browser window and keeps those values in sync as the window is resized. Resize events are debounced (200 ms by default) using useDebouncedCallback to avoid flooding your component with updates during a drag. The hook is also server-side rendering safe — both dimensions are undefined when there is no window object, preventing hydration mismatches in Next.js and similar frameworks.
Installation
Signature
Parameters
useWindowResize takes no parameters.
Return Value
The current
window.innerWidth in pixels. undefined during server-side rendering or before the initial effect runs.The current
window.innerHeight in pixels. undefined during server-side rendering or before the initial effect runs.Usage
Responsive Layout
Conditional Rendering Based on Breakpoint
Dynamic Canvas Size
Notes
- Resize events are debounced with a 200 ms delay via the internal
useDebouncedCallbackhook. This keeps your component responsive without triggering a re-render for every pixel of a resize drag. - On the server (
typeof window === 'undefined'), bothwidthandheightare initialised toundefined. Always provide a fallback (e.g.width ?? 0) before doing arithmetic or comparisons. - The hook uses
useEventListenerinternally to attach and clean up the'resize'listener, so you never need to callremoveEventListenermanually. - This hook depends on
useDebouncedCallbackanduseEventListener. Both are installed automatically when you use the CLI command above.