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

0.0.18 • Public • Published

@burst/react-use-window-size

React custom hook to get viewport width and height on init and resize

installation

npm i @burst/react-use-window-size

Example

import React from 'react'
import { useWindowSize } from '@burst/use-window-size'

const Component = () => {
  const { viewportWidth, viewportHeight, documentWidth, documentHeight } = useWindowSize()

  return (
    <div>
      {viewportWidth}x{viewportHeight}px
    </div>
  )
}

export default Component

Mobile check is done to prevent a resize event trigger when safari url bar change. So using orientationchange on mobile devices. A throttle is used to prevent too many resize events.

Package Sidebar

Install

npm i @burst/react-use-window-size

Weekly Downloads

10

Version

0.0.18

License

MIT

Unpacked Size

19 kB

Total Files

10

Last publish

Collaborators

  • dennistimmers
  • robinheij
  • joriregter
  • burst-bot
  • carinhansen
  • perryjanssen
  • fvanharreveld