Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | /**
* The size of the browser window.
*/
export interface WindowSize {
/**
* The width of the window in pixels.
*/
width: number;
/**
* The height of the window in pixels.
*/
height: number;
}
/**
* Callback fired whenever the tracked window size changes.
*
* @param size - The new window size
*/
export type OnWindowSizeChange = (size: WindowSize) => void;
/**
* Options for configuring the useWindowSize hook.
*/
export interface UseWindowSizeOptions {
/**
* Width returned before the window can be measured (SSR / first server render).
* @default 0
*/
initialWidth?: number;
/**
* Height returned before the window can be measured (SSR / first server render).
* @default 0
*/
initialHeight?: number;
/**
* Debounce resize updates by this many milliseconds.
* Only the last resize within the window is applied. Mutually exclusive with
* `throttleMs` — if both are set, `debounceMs` takes precedence.
* @default 0
*/
debounceMs?: number;
/**
* Throttle resize updates to at most once per this many milliseconds.
* Ignored when `debounceMs` is set.
* @default 0
*/
throttleMs?: number;
/**
* Whether to include the scrollbar in the measured size.
* When `true`, uses `window.innerWidth`/`innerHeight` (includes scrollbar).
* When `false`, uses `document.documentElement.clientWidth`/`clientHeight`
* (excludes scrollbar).
* @default true
*/
includeScrollbar?: boolean;
/**
* Whether size tracking is enabled.
* When `false`, no resize listener is attached and the last known size is kept.
* @default true
*/
enabled?: boolean;
/**
* Callback fired whenever the window size changes.
*
* @example
* ```tsx
* useWindowSize({
* onChange: ({ width }) => {
* if (width < 768) closeSidebar();
* },
* });
* ```
*/
onChange?: OnWindowSizeChange;
}
/**
* Return value of the useWindowSize hook: the current window size.
*/
export type UseWindowSizeReturn = WindowSize;
|