useOrientation

React sensor hook that tracks screen orientation of user's device.

Returns state in the following shape

Usage

import { useOrientation } from "@reactuses/core";

const Demo = () => {
  const [state] = useOrientation();

  return <pre>{JSON.stringify(state, null, 2)}</pre>;
};

Example

{
  "angle": 0,
  "type": "landscape-primary"
}

Type Declarations

export interface OrientationState {
  angle: number
  type: string
}
export default function useOrientation(
  initialState?: OrientationState
): readonly [
  OrientationState,
  (type: OrientationLockType) => Promise<void> | undefined,
  () => void
]