@react-typed-hooks/use-window-size
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

useWindowSize

React hook that returns the window size. Updates on window resize and orientation change.

version

Installation

npm install @react-typed-hooks/use-window-size

Usage

import { useWindowSize } from "@react-typed-hooks/use-window-size";

const Demo = () => {
  const size = useWindowSize();

  return size ? (
    <pre>JSON.stringify(size, null, 4)</pre>
  ) : (
    <span>Size is null in a node like environment</span>
  );
};

API

Types

interface Size {
  height: number;
  width: number;
}

interface UseWindowSizeOptions {
  wait?: number;
}
function useWindowSize(options?: UseWindowSizeOptions): Size | null;

Options

wait

The amount of time to delay updating Size after the orientation changes.

The amount of time to throttle between updating Size when the window is resized.

Readme

Keywords

Package Sidebar

Install

npm i @react-typed-hooks/use-window-size

Weekly Downloads

12

Version

1.0.5

License

MIT

Unpacked Size

8.61 kB

Total Files

12

Last publish

Collaborators

  • cjdierkens