Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 802 Bytes

File metadata and controls

39 lines (27 loc) · 802 Bytes

useWindowSize

Returns the current window dimensions. Updates automatically when the window is resized.

Import

import { useWindowSize } from "@hemilabs/react-hooks/useWindowSize";

Parameters

None.

Return Value

Property Type Description
height number Current window height in pixels
width number Current window width in pixels

Both values default to 0 during server-side rendering.

Usage

import { useWindowSize } from "@hemilabs/react-hooks/useWindowSize";

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

  return (
    <div>
      Window: {width}x{height}
      {width < 768 && <MobileNav />}
    </div>
  );
}