useScreenSize

Returns window width and height, updating on resize.

Returns window width and height, updating on resize. During server rendering the initial values are 0 × 0; after mounting the hook reads the window size.

Usage

'use client';

import { useScreenSize } from '@prosazhin/pbcomponents';

function Example() {
  const { width, height } = useScreenSize();
  return (
    <span>
      {width} × {height}
    </span>
  );
}

Hook API

Returns

ValueType / variantsPurpose
widthnumberWindow width in pixels.
heightnumberWindow height in pixels.

On this page