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

1.7.0 • Public • Published

useWindowSize

Get the width and height of the viewport.

Checkout the Storybook demo.

Installation

yarn add @charlietango/use-window-size

API

const { width, height } = useWindowSize()

By default, the value is lazy to support SSR, so the width and height will always be 0 on the initial render. Subsequent users of the hook will return the size during the first render.

Example

import React from 'react'
import useWindowSize from '@charlietango/use-window-size'

const Component = () => {
  const { width, height } = useWindowSize()

  return (
    <div>
      {width}x{height}px
    </div>
  )
}

export default Component

Readme

Keywords

Package Sidebar

Install

npm i @charlietango/use-window-size

Weekly Downloads

78

Version

1.7.0

License

MIT

Unpacked Size

5.42 kB

Total Files

6

Last publish

Collaborators

  • thebuilder
  • frederik_bosch