2.0.0 • Published 1 year ago

use-dimensions v2.0.0

Weekly downloads
139
License
MIT
Repository
-
Last release
1 year ago

useDimensions Tweet

A React hook for the React Native Dimensions API.

version minified size minzipped size downloads build

Install

  • npm install use-dimensions --save, or
  • yarn add use-dimensions

Use

Screen and Window Dimensions

To get both screen and window dimensions, use the default export.

import useDimensions from 'use-dimensions';

const MyComponent = () => {
  const { screen, window } = useDimensions();
  return <Text>{screen.width}x{screen.height} inside {window.width}x{window.height}</Text>;
}

Screen Dimensions Only

To get the screen dimensions only, use the useScreenDimensions export.

import { useScreenDimensions } from 'use-dimensions';

const MyComponent = () => {
  const { height, width } = useScreenDimensions();
  return <Text>{width}x{height}</Text>;
}

Window Dimensions Only

To get the window dimensions only, use the useWindowDimensions export.

import { useWindowDimensions } from 'use-dimensions';

const MyComponent = () => {
  const { height, width } = useWindowDimensions();
  return <Text>{width}x{height}</Text>;
}

Sponsor 💗

If you are a fan of this project, you may become a sponsor via GitHub's Sponsors Program.

2.0.0

1 year ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago