use-dimensions
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

useDimensions

version minzipped size downloads

useDimensions is a React hook for the React Native Dimensions API.

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';

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

Screen Dimensions Only

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

import { useScreenDimensions } from 'use-dimensions';

export default function 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';

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

Readme

Keywords

none

Package Sidebar

Install

npm i use-dimensions

Weekly Downloads

8

Version

2.0.0

License

MIT

Unpacked Size

6.4 kB

Total Files

9

Last publish

Collaborators

  • charlesstover