use-browser-permissions
v0.0.1
Published
React hook to manage browser permissions like geolocation, notifications, and more.
Maintainers
Readme
🎯 usePermissions
A fully-typed, browser-safe React hook for managing permission requests like geolocation, notifications, microphone, and more — with support for automatic requests, change listeners, and error handling.
Built with TypeScript. Lightweight. No dependencies.
📦 Installation
npm install use-browser-permissions✨ Features ✅ Supports geolocation, notifications, camera, microphone, etc.
✅ Built-in request() and check() functions
✅ Auto-request option on mount
✅ onStatusChange listener support
✅ Tracks granted, denied, prompt states
✅ Error handling included
✅ Fully typed with TypeScript
🧪 Usage
import React from 'react';
import {usePermissions} from 'use-browser-permissions';
export default function App() {
const { status, request, isGranted } = usePermissions('geolocation');
return (
<div>
<p>Permission status: {status}</p>
<button onClick={request} disabled={isGranted}>
Request Geolocation
</button>
</div>
);
};| Name | Type | Description |
| ------------ | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| permission | string or { name: string } | The permission to check/request (e.g. 'geolocation', 'notifications') |
| options | { request?: boolean; onStatusChange?: (status: 'granted' \| 'denied' \| 'prompt') => void } | Optional config: auto request and status change callback |
