raddix

useWindowSize

Keeps track of the dimensions of the browser window.

Installation

npm i @raddix/use-window-size

Usage

Basic Usage

import React from 'react';
import { useWindowSize } from '@raddix/use-window-size';
const App = () => {
const { width, height } = useWindowSize();
return (
<div>
<h1>Window size</h1>
<p>Width: {width}</p>
<p>Height: {height}</p>
</div>
);
};

API

Returns

The useWindowSize hook returns an object with the following properties:

Return valueDescriptionType
widthThe current width of the window, in pixels.number
heightThe current height of the window, in pixels.number