Licence
MIT
Version
1.0.9
Deps
0
Size
7 kB
Vulns
0
Weekly
0
React useDeviceOrientation Hook
Install
npm i react-use-device-orientation
Usage
- Import
useDeviceOrientationhook. - Call
requestAccesswhich prompts the use to grant permission on iOS. - Use the
orientationdata.
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