Skip to content

πŸ“¦ npm package: React βš›οΈ hook that returns a pixel value for a given percentage of viewport πŸ“ width, updating automatically on resize for responsive layouts

gass-git/use-viewport-width

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Install with NPM

npm i use-viewport-width

Parameter

Name Type Description
percentage number The percentage of the viewport width to calculate. The hook returns this percentage of the current viewport width in pixels. For example, 50 will return 50% of the viewport width.

Usage

import useVW from 'use-viewport-width'

const w = useVW(100) // 100% of the viewport width in pixels

Example

import useVW from "use-viewport-width"

function Box() {
  const w = useVW(50) // 50% of viewport width

  return (
    <div style={{ width: `${w}px`, background: "blue", height: "100px" }}>
      responsive box - width: {w}px
    </div>
  )
}

About

πŸ“¦ npm package: React βš›οΈ hook that returns a pixel value for a given percentage of viewport πŸ“ width, updating automatically on resize for responsive layouts

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published