#78SensorsEasy

useWindowSize

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

// TODO: implement useWindowSize
function notImplemented(..._args: any[]): any {
  throw new Error('Not implemented');
}
export default notImplemented;
export const useWindowSize = notImplemented;

Open browser consoleTests