New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-viewport-hooks

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-viewport-hooks

Get real viewport width & height

latest
Source
npmnpm
Version
1.5.0
Version published
Weekly downloads
247
10.27%
Maintainers
1
Weekly downloads
 
Created
Source

react-viewport-hooks

NPM version NPM downloads

About

Get real viewport width & height

How to Install

First, install the library in your project by npm:

$ npm install react-viewport-hooks

Or Yarn:

$ yarn add react-viewport-hooks

Getting Started

Options

NameTypeDefaultDescription
updateOnResizebooleantrueUpdate sizes on window resize
defaultVWnumberundefinedFallback for default vw value
defaultVHnumberundefinedFallback for default vh value

Returned Values

NameTypeDescription
vwnumberWindow viewport width
vhnumberWindow viewport height

Example

useViewport hook:

import React from 'react';
import { useViewport } from 'react-viewport-hooks';

const App = () => {
  const { vw, vh } = useViewport(/* object with options (if needed) */);

  document.documentElement.style.setProperty('--vw', `${vw}px`);
  document.documentElement.style.setProperty('--vh', `${vh}px`);

  return <h1>Hello Viewport!</h1>;
};

export default App;

withViewport HOC:

import React from 'react';
import { withViewport } from 'react-viewport-hooks';

const App = ({ vw, vh }) => {
  document.documentElement.style.setProperty('--vw', `${vw}px`);
  document.documentElement.style.setProperty('--vh', `${vh}px`);

  return <h1>Hello Viewport!</h1>;
};

export default withViewport(/* object with options (if needed) */)(App);

License

This project is licensed under the MIT License © 2019-present Jakub Biesiada

Keywords

viewport

FAQs

Package last updated on 01 Jun 2020

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