Skip to main content
Version: Next

useWindowDimension

This hook provides a way to measure the window/document. It handles the resize of the window.

Arguments

callback [ function ]

First argument is a callback function with event object as its first argument which is called initially and is called on every resize of a window.

Here are the properties of an event object argument of a callback function:

PropertyDescription
widthWidth of a documentElement
heightHeight of a documentElement
innerWidthWidth of a window. Gives window.innerWidth
innerHeightHeight of a window. Gives window.innerHeight

deps [ array ]

Optional array of values which re-initiates the callback function when changed.

Returns

Void

Example

In the below example, useWindowDimension hook is used to measure the innerWidth of a window.

import { useWindowDimension } from "react-ui-animate";

export default function() {

useWindowDimension(
function ({ innerWidth }) {
console.log("window inner width", innerWidth);
},
);

return (...);
}