跳到主要内容

usePermission

浏览器权限查询

Usage

实时编辑器

function Demo() {
  const state = usePermission({ name: "microphone" });

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

结果
Loading...

API

usePermission

Returns

UsePermissionState: 权限状态

Arguments

参数名描述类型默认值
permissionDesc权限描述符UsePermissionGeneralPermissionDescriptor | "geolocation" | "notifications" | "persistent-storage" | "push" | "screen-wake-lock" | "xr-spatial-tracking" | "accelerometer" | "accessibility-events" | "ambient-light-sensor" | "background-sync" | "camera" | "clipboard-read" | "clipboard-write" | "gyroscope" | "magnetometer" | "microphone" | "payment-handler" | "speaker" (必填)-

UsePermissionState

Type

export type UsePermissionState = PermissionState | ''

UsePermissionGeneralPermissionDescriptor

Type

export type UsePermissionGeneralPermissionDescriptor = | PermissionDescriptor | { name: UsePermissionDescriptorNamePolyfill }

UsePermissionDescriptorNamePolyfill

Type

export type UsePermissionDescriptorNamePolyfill = | 'accelerometer' | 'accessibility-events' | 'ambient-light-sensor' | 'background-sync' | 'camera' | 'clipboard-read' | 'clipboard-write' | 'gyroscope' | 'magnetometer' | 'microphone' | 'notifications' | 'payment-handler' | 'persistent-storage' | 'push' | 'speaker'