Skip to content

useWindowSize

Hook that manages a window size

elements
low
test coverage
Last changed: 5 months ago

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

SourceDemo

Contributors

D
debabin
debabin
G
gwizxs
gwizxs
H
hywax
hywax

Released under the MIT License.