Skip to content

Latest commit

Β 

History

History
36 lines (25 loc) Β· 664 Bytes

useWindowSize.md

File metadata and controls

36 lines (25 loc) Β· 664 Bytes

useWindowSize

React sensor hook that tracks dimensions of the browser window.

Usage

import {useWindowSize} from 'react-use';

const Demo = () => {
  const {width, height} = useWindowSize();

  return (
    <div>
      <div>width: {width}</div>
      <div>height: {height}</div>
    </div>
  );
};

Reference

useWindowSize(options);
  • initialWidth β€” Initial width value for non-browser environments.
  • initialHeight β€” Initial height value for non-browser environments.
  • onChange β€” Callback function triggered when the window size changes.

Related hooks