Skip to content

Commit 3b884bd

Browse files
authored
Merge pull request #109 from frontend-opensource-project/URH-111/use-permission
[URH-111] usePermission 문서
2 parents 983b8b2 + 3772d6c commit 3b884bd

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

docs/pages/hooks/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"useMousePosition": "useMousePosition",
1919
"useOnlineStatus": "useOnlineStatus",
2020
"useOutsideClick": "useOutsideClick",
21+
"usePermission": "usePermission",
2122
"usePrefersColorScheme": "usePrefersColorScheme",
2223
"usePreventCopy": "usePreventCopy",
2324
"useScrollLock": "useScrollLock",

docs/pages/hooks/usePermission.mdx

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# usePermission
2+
3+
## Introduce
4+
5+
사용자의 권한 상태의 변화를 감지하고, 권한 요청에 대한 상태를 자동으로 처리하는 훅입니다.
6+
7+
```ts
8+
interface UsePermissionProps {
9+
permission:
10+
| 'accessibility-events'
11+
| 'accelerometer'
12+
| 'ambient-light-sensor'
13+
| 'background-fetch'
14+
| 'background-sync'
15+
| 'bluetooth'
16+
| 'camera'
17+
| 'captured-surface-control'
18+
| 'clipboard-read'
19+
| 'clipboard-write'
20+
| 'display-capture'
21+
| 'fullscreen'
22+
| 'geolocation'
23+
| 'gyroscope'
24+
| 'idle-detection'
25+
| 'keyboard-lock'
26+
| 'local-fonts'
27+
| 'magnetometer'
28+
| 'microphone'
29+
| 'midi'
30+
| 'nfc'
31+
| 'notifications'
32+
| 'payment-handler'
33+
| 'periodic-background-sync'
34+
| 'persistent-storage'
35+
| 'pointer-lock'
36+
| 'push'
37+
| 'screen-wake-lock'
38+
| 'speaker-selection'
39+
| 'storage-access'
40+
| 'system-wake-lock'
41+
| 'top-level-storage-access'
42+
| 'window-management';
43+
}
44+
45+
interface UsePermissionReturns {
46+
status: 'granted' | 'prompt' | 'denied' | 'notSupported';
47+
}
48+
49+
const useSomethingHook = (props: UsePermissionProps): UsePermissionReturns
50+
```
51+
52+
- 주어진 권한에 대한 상태를 확인하고, 권한 상태가 변경될 때마다 업데이트합니다.
53+
54+
### Props
55+
56+
- `permission` : 확인하려는 권한의 이름을 입력합니다. `Permission` 타입은 사전 정의된 권한 이름과 문자열 모두 허용됩니다.
57+
58+
import { Callout } from 'nextra/components';
59+
60+
<Callout type="info">
61+
사전 정의된 권한은 Firefox, Chromium, WebKit에서 공통으로 사용하는 권한입니다.
62+
</Callout>
63+
64+
### Returns
65+
66+
- `status` : 현재 권한의 상태를 반환합니다.
67+
68+
<Callout type="info">
69+
상태 값은 다음 중 하나일 수 있습니다: `granted` | `prompt` | `denied` |
70+
`notSupported`
71+
</Callout>
72+
73+
<Callout type="error">
74+
클라이언트 환경이 아니거나 Permissions API가 지원되지 않는 경우, 권한 상태가
75+
'notSupported'로 설정됩니다.
76+
</Callout>
77+
78+
## Examples
79+
80+
```tsx copy filename="TestComponent.tsx"
81+
import React from 'react';
82+
import usePermission from './usePermission';
83+
84+
const TestComponent = () => {
85+
const { status } = usePermission({ permission: 'geolocation' }); // prompt
86+
87+
return (
88+
<div>
89+
<h1>권한 상태: {status}</h1>
90+
</div>
91+
);
92+
};
93+
94+
export default TestComponent;
95+
```

0 commit comments

Comments
 (0)