Skip to content

useDeviceOrientation

Hook that provides the current device orientation

sensors
low
test coverage
Last changed: 6 months ago

Installation

Library
CLI
Manual
typescript
import { useDeviceOrientation } from '@siberiacancode/reactuse';

Usage

typescript
const { supported, value } = useDeviceOrientation();
## Demo

Api

Returns

UseDeviceOrientationReturn

Type declaration

typescript
export interface UseDeviceOrientationValue {
  /** The current absolute value */
  absolute: boolean;
  /** A number representing the motion of the device around the z axis, express in degrees with values ranging from 0 to 360 */
  alpha: number | null;
  /** A number representing the motion of the device around the x axis, express in degrees with values ranging from -180 to 180 */
  beta: number | null;
  /** A number representing the motion of the device around the y axis, express in degrees with values ranging from -90 to 90 */
  gamma: number | null;
}

export interface UseDeviceOrientationReturn {
  /** Whether the device orientation is supported */
  supported: boolean;
  /** The current device orientation value */
  value: UseDeviceOrientationValue;
}

Source

SourceDemo

Contributors

D
debabin
debabin
B
babin
babin

Released under the MIT License.