Skip to content

Instantly share code, notes, and snippets.

@swiety85
swiety85 / withOrientation.js
Last active June 2, 2021 15:51
React Native HOC (Higher Order Component) that adds 'orientation' and 'isLandscape' props to the component
import React, { useState, useEffect } from 'react';
import { Dimensions } from 'react-native';
const getOrientation = () => Dimensions.get('window').width < Dimensions.get('window').height ? 'portrait' : 'landscape';
export default function withOrientation(WrappedComponent) {
return function (props) {
const [orientation, setOrientation] = useState(getOrientation());