Skip to main content

useWindowSize

Get window size.

API

function useWindowSize(): {
width: number | undefined;
height: number | undefined;
};

Example

You can change the browser window size to see the effect.

Window size: {"width":0,"height":0}
import React from "react";
import { useWindowSize } from "@lilib/hooks";

function Example() {
const { width = 0, height = 0 } = useWindowSize();

return <>Window size: {JSON.stringify({ width, height })}</>;
}

export default Example;