Loading...
Please waitLoading...
Please waitpnpm dlx uselab@latest add use-permission
import { usePermission } from "@/hooks/use-permission"
export function PermissionGate() {
const { state, refresh } = usePermission("notifications")
return (
<div className="space-y-2">
<p>Notifications: {state || "unknown"}</p>
<button onClick={() => void refresh()}>Refresh</button>
</div>
)
}usePermission(name)| Name | Type | Description | Optional |
|---|---|---|---|
name | string | Permission name passed to the browser Permissions API. | No |
The hook returns an object { isSupported, state, error, refresh }:
| Name | Type | Description |
|---|---|---|
isSupported | boolean | Whether navigator.permissions exists. |
state | "granted" | "denied" | "prompt" | null | Current permission state, or null if unavailable. |
error | Error | null | Last query error. |
refresh | () => Promise<"granted" | "denied" | "prompt" | null> | Re-queries the permission state. |
Notifications
Unknown
Geolocation
Unknown