Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/charliehess/orientation-observer

Render React components based on window aspect ratio
https://github.com/charliehess/orientation-observer

Last synced: 7 days ago
JSON representation

Render React components based on window aspect ratio

Awesome Lists containing this project

README

        

# orientation-observer
Allows you to render components selectively based on aspect ratio.

## How so?
It listens for window `resize` events and compares `window.innerWidth` and `window.innerHeight`. If height is greater, only components with `orientation='portrait'` will be rendered. If width is greater, components with `orientation='landscape'` will be rendered. This is inspired by https://github.com/zeroseven/react-screen-orientation, but instead of using `@media` queries for detecting orientation we'll just use window size.

## Quick-start

```
npm install orientation-observer
```

```javascript
import React, { Component } from 'react'

import { OrientationObserver, Orientation } from 'orientation-observer'

class App extends Component {
render () {
return (

{/* Will only be rendered in landscape */}


Only visible in landscape




{/* Will only be rendered in portrait */}


Please rotate your device





);
}
}
```