Socket
Book a DemoInstallSign in
Socket

@buildinams/use-window-size

Package Overview
Dependencies
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@buildinams/use-window-size

Hook to get the viewport bounds (width and height)

0.0.1
latest
Source
npmnpm
Version published
Weekly downloads
189
-41.67%
Maintainers
3
Weekly downloads
 
Created
Source

use-window-size

NPM version Actions Status PR Welcome

Hook to get the viewport bounds (width and height).

Introduction

This hook optimizes window resize event handling by:

  • Only initializing a single event listener for all instance of the hook used.
  • Throttling how often the event resize handler fires (Max 200ms between calls).

This library is also SSR safe, and only runs on the client.

Installation

Install this package with npm.

npm i @buildinams/use-window-size

Usage

To use this hook, simply import it and use it like a normal React hook.

import useWindowSize from "@buildinams/use-window-size";

const { width, height } = useWindowSize();

API

On first render this hooks returns 0 for both window width and height and then returns window width and height once is mounted.

Requirements

This library requires a minimum React version of 17.0.0.

Requests and Contributing

Found an issue? Want a new feature? Get involved! Please contribute using our guideline here.

Keywords

react

FAQs

Package last updated on 03 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.