useOrientation

React 传感器钩子,跟踪用户设备的屏幕方向。

以以下形式返回状态:

  1. {
  2. angle: 0,
  3. type: 'landscape-primary'
  4. }

用法

  1. import {useOrientation} from 'react-use';
  2. const Demo = () => {
  3. const state = useOrientation();
  4. return (
  5. <pre>
  6. {JSON.stringify(state, null, 2)}
  7. </pre>
  8. );
  9. };