A lightweight React Native hook to detect device screen orientation (PORTRAIT
or LANDSCAPE
) in real time.
- π Detects screen orientation changes dynamically
- πͺΆ Lightweight and dependency-free
- βοΈ Works seamlessly with React Native functional components
- β Written in TypeScript
npm install @el173/react-native-use-orientation
# or
yarn add @el173/react-native-use-orientation
import React from 'react';
import { Text, View } from 'react-native';
import { useOrientation } from '@el173/react-native-use-orientation';
const App = () => {
const orientation = useOrientation();
return (
<View>
<Text>Current Orientation: {orientation}</Text>
</View>
);
};
export default App;
A React hook that detects the current screen orientation and updates automatically on change.
'PORTRAIT'
β when the screen height is greater than or equal to its width'LANDSCAPE'
β when the screen width is greater than its height
If the device is rotated:
Current Orientation: LANDSCAPE
Otherwise:
Current Orientation: PORTRAIT
MIT
Hashith Karunarathne
Website: hashith.com GitHub: el173
You can use this hook to conditionally render different layouts or styles based on orientation in your React Native app!