A reactive hook that observes and synchronizes browser permission statuses in real-time.
Caution
The Permissions API does not support all features uniformly. Passing certain strings (like 'camera') to the observer may throw errors in browsers where those specific permission names are not yet implemented.
Note
This hook only observes existing status changes. It cannot trigger the permission prompt itself.
Installation
bash
Description
The usePermissions hook provides a declarative way to monitor the status of various browser features (such as camera access, geolocation, or notifications). It abstracts the complexities of the Permissions API by handling the initial asynchronous query and subscribing to state changes automatically. This allows the UI to react instantly when the user modifies permissions via the browser's settings bar.
Parameters
Name
Type
Description
permissionNames
readonly PermissionName[]
An array of permission names to observe. This parameter is required and has not default.
Return values
Name
Type
Description
isSupported
boolean
Returns true if the current environment/browser supports the native Permissions API.
permissions
PermissionsSnapshot
A reactive object where keys are the permission names and values are the current state: 'granted', 'denied', or 'prompt'.