Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/CharlesStover/use-dimensions

A React hook for the React Native Dimensions API.
https://github.com/CharlesStover/use-dimensions

npm npmjs react react-hook react-hooks react-native reactjs reactnative typescript

Last synced: about 1 month ago
JSON representation

A React hook for the React Native Dimensions API.

Awesome Lists containing this project

README

        

# useDimensions

[![version](https://img.shields.io/npm/v/use-dimensions.svg)](https://www.npmjs.com/package/use-dimensions)
[![minzipped size](https://img.shields.io/bundlephobia/minzip/use-dimensions.svg)](https://www.npmjs.com/package/use-dimensions)
[![downloads](https://img.shields.io/npm/dt/use-dimensions.svg)](https://www.npmjs.com/package/use-dimensions)

`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.

```js
import useDimensions from 'use-dimensions';

export default function MyComponent() {
const { screen, window } = useDimensions();
return (

a {screen.width}x{screen.height} screen{' '}
inside a{' '}
{window.width}x{window.height} window

);
}
```

### Screen Dimensions Only

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

```js
import { useScreenDimensions } from 'use-dimensions';

export default function MyComponent() {
const { height, width } = useScreenDimensions();
return {width}x{height};
}
```

### Window Dimensions Only

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

```js
import { useWindowDimensions } from 'use-dimensions';

export default function MyComponent() {
const { height, width } = useWindowDimensions();
return {width}x{height};
}
```