跳至主要内容

useOrientation

跟蹤用戶設備的螢幕方向。

Usage

即時編輯器

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

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

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

API

useOrientation

Returns

readonly [UseOrientationState, (type: UseOrientationLockType) => any, () => void]: 包含以下元素的元組:

  • 方向狀態。
  • 鎖定方向。
  • 解鎖方向。

Arguments

參數名描述類型預設值
initialState初始值UseOrientationState | undefined-

UseOrientationState

參數名描述類型預設值
angle角度number (必填)-
type方向类型UseOrientationType | undefined (必填)-

UseOrientationType

Type

export type UseOrientationType = | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary'

UseOrientationLockType

Type

export type UseOrientationLockType = | 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary'

ads via Carbon