Skip to content

useWindowSize ​

Hook that manages a window size

elements
test coverage
Last changed: last month

Installation ​

Library
CLI
Manual
typescript
import { useWindowSize } from '@siberiacancode/reactuse';

Usage ​

typescript
const { width, height } = useWindowSize();

Demo ​

Api ​

Parameters

NameTypeDefaultNote
params.initialWidth?numberNumber.POSITIVE_INFINITYThe initial window width
params.initialHeight?numberNumber.POSITIVE_INFINITYThe initial window height

Returns

UseWindowSizeReturn

Type declaration ​

typescript
interface UseWindowSizeParams {
  /** Whether to include the scrollbar in the window size calculation */
  includeScrollbar?: boolean;
}

export interface UseWindowSizeReturn {
  /** The current window height */
  height: number;
  /** The current window width */
  width: number;
}

Source ​

Source • Demo

Contributors ​

D
debabin
debabin
H
hywax
hywax

Released under the MIT License.