@react-hookz/web
Version:
React hooks done right, for browser and SSR.
12 lines (11 loc) • 469 B
JavaScript
import { useMediaQuery } from '..';
/**
* Checks if screen is in `portrait` or `landscape` orientation.
*
* As `Screen Orientation API` is still experimental and not supported by Safari, this
* hook uses CSS3 `orientation` media-query to check screen orientation.
*/
export function useScreenOrientation() {
const matches = useMediaQuery('(orientation: portrait)');
return typeof matches === 'undefined' ? undefined : matches ? 'portrait' : 'landscape';
}