react-use-device-orientation
v1.0.9
Published
A React hook to use device orientation on a website.
Downloads
9
Readme
React useDeviceOrientation Hook
Install
npm i react-use-device-orientation
Usage
- Import
useDeviceOrientation
hook. - Call
requestAccess
which prompts the use to grant permission on iOS. - Use the
orientation
data.
import { useDeviceOrientation } from 'react-use-device-orientation'
// ...
const { orientation, requestAccess, revokeAccess, error } = useDeviceOrientation()
To obtain absolute orientation pass "absolute"
to the hook as a parameter.
const { orientation, requestAccess, revokeAccess, error } = useDeviceOrientation('absolute')
More Info
https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent#browser_compatibility