Skip to content

Commit faca67a

Browse files
authored
docs: update documentation for useBodyScrollLock, useNetworkStatus, usePageVisibility, and useScrollDirection hooks (toss#311)
1 parent 8c94727 commit faca67a

11 files changed

Lines changed: 2656 additions & 244 deletions

File tree

docs/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: home
33

44
hero:
55
name: 'react-simplikit'
6-
text: 'React utility library family'
6+
text: 'Lightweight and powerful React utility library'
77
image:
88
src: /images/symbol.svg
99
alt: react-simplikit
@@ -16,10 +16,10 @@ hero:
1616
link: /core/intro
1717

1818
features:
19-
- title: '@react-simplikit/mobile'
20-
details: Mobile-optimized hooks for web views and hybrid apps. Handle keyboard, viewport, scroll issues.
21-
link: /mobile/intro
22-
- title: react-simplikit
23-
details: Core utilities, hooks, and components for React applications. Zero dependencies.
24-
link: /core/intro
19+
- title: 'Zero dependencies'
20+
details: No external libraries are needed, making your project lightweight, faster, and easier to maintain. Effortlessly reduce bundle size and improve performance.
21+
- title: 100% Test Coverage
22+
details: Every function and branch is rigorously tested, ensuring robust and reliable code for any use case.
23+
- title: Comprehensive Documentation
24+
details: Each feature includes clear JSDoc comments, beginner-friendly guides, and practical examples. Start quickly with detailed and easy-to-follow instructions.
2525
---

docs/ko/index.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: home
33

44
hero:
55
name: 'react-simplikit'
6-
text: 'React 유틸리티 라이브러리 패밀리'
6+
text: '가볍고 강력한 React 유틸리티 라이브러리'
77
image:
88
src: /images/symbol.svg
99
alt: react-simplikit
@@ -16,10 +16,10 @@ hero:
1616
link: /ko/core/intro
1717

1818
features:
19-
- title: '@react-simplikit/mobile'
20-
details: 모바일 웹뷰와 하이브리드 앱을 위한 최적화된 훅. 키보드, 뷰포트, 스크롤 이슈를 해결합니다.
21-
link: /ko/mobile/intro
22-
- title: react-simplikit
23-
details: React 애플리케이션을 위한 핵심 유틸리티, 훅, 컴포넌트. 의존성 없음.
24-
link: /ko/core/intro
19+
- title: '의존성이 전혀 없어요'
20+
details: 추가 라이브러리가 필요 없어서 프로젝트가 가볍고 빠르며 유지보수가 쉬워요. 번들 크기를 줄이고 성능을 손쉽게 개선할 수 있어요.
21+
- title: 100% 테스트 커버리지
22+
details: 모든 함수와 분기를 꼼꼼히 테스트해서 어떤 상황에서도 안정적이고 신뢰할 수 있는 코드를 보장해요.
23+
- title: 풍부한 문서
24+
details: 각 기능에 대해 명확한 JSDoc, 초보자도 이해하기 쉬운 가이드, 실용적인 예제가 포함되어 있어요. 자세하고 따라 하기 쉬운 설명으로 바로 시작할 수 있어요.
2525
---
Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# useBodyScrollLock
22

3-
A React hook that locks body scroll when mounted and automatically unlocks when unmounted. This is particularly useful for modals, drawers, and other overlay components that should prevent background scrolling.
4-
53
## Interface
64

75
```ts
@@ -10,50 +8,20 @@ function useBodyScrollLock(): void;
108

119
### Parameters
1210

13-
This hook takes no parameters.
14-
1511
### Return Value
1612

17-
This hook returns `void` (no return value).
13+
This hook does not return anything.
1814

19-
## Examples
20-
21-
### Basic Usage
15+
## Example
2216

17+
````tsx
2318
```tsx
2419
function Modal() {
2520
useBodyScrollLock();
2621
return <div className="modal">Modal content</div>;
2722
}
28-
```
29-
30-
### Multiple Modals - Single Lock Pattern
31-
32-
When you have multiple overlapping modals, use a single lock at the parent level instead of applying the lock to each modal individually.
33-
34-
```tsx
35-
// Multiple modals - single lock pattern
36-
function BodyScrollLock() {
37-
useBodyScrollLock();
38-
return null;
39-
}
40-
41-
function App() {
42-
const hasModal = showModal1 || showModal2;
23+
````
4324
44-
return (
45-
<>
46-
{hasModal && <BodyScrollLock />}
47-
{showModal1 && <Modal1 />}
48-
{showModal2 && <Modal2 />}
49-
</>
50-
);
51-
}
5225
```
5326

54-
## Notes
55-
56-
- **SSR Safety**: This hook uses `useEffect`, which only runs on the client side, making it safe for server-side rendering (SSR).
57-
- **Automatic Cleanup**: The scroll lock is automatically removed when the component unmounts, ensuring proper cleanup.
58-
- **Multiple Modals**: For scenarios with multiple overlapping modals, implement a single lock at the parent level rather than applying locks to each modal individually. This prevents conflicts and ensures consistent behavior.
59-
- **Browser Support**: Works in all modern browsers that support the underlying CSS modifications applied by the `enableBodyScrollLock` and `disableBodyScrollLock` utilities.
27+
```

packages/mobile/src/hooks/useNetworkStatus/ko/useNetworkStatus.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ description="네트워크 연결 데이터를 담은 객체예요."
2121
:nested="[
2222
{
2323
name: 'effectiveType',
24-
type: \"'slow-2g' | '2g' | '3g' | '4g' | undefined\",
24+
type: &quot;'slow-2g' | '2g' | '3g' | '4g' | undefined&quot;,
2525
required: false,
2626
description: '연결 품질 지표 - API가 지원되지 않으면 undefined',
2727
},
2828
{
2929
name: 'type',
30-
type: \"'bluetooth' | 'cellular' | 'ethernet' | 'mixed' | 'none' | 'other' | 'unknown' | 'wifi' | 'wimax' | undefined\",
30+
type: &quot;'bluetooth' | 'cellular' | 'ethernet' | 'mixed' | 'none' | 'other' | 'unknown' | 'wifi' | 'wimax' | undefined&quot;,
3131
required: false,
3232
description: '물리적 연결 타입 - API가 지원되지 않으면 undefined',
3333
},
Lines changed: 21 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# useNetworkStatus
22

3-
React hook to access Network Information API. Provides raw network connection data including connection type, quality, speed, and user preferences. Returns undefined for all properties if the API is not supported (e.g., Safari, Firefox).
4-
53
## Interface
64

75
```ts
@@ -10,99 +8,42 @@ function useNetworkStatus(): NetworkStatus;
108

119
### Parameters
1210

13-
This hook takes no parameters.
14-
1511
### Return Value
1612

1713
<Interface
18-
name=""
19-
type="NetworkStatus"
20-
description="object with network connection data."
21-
:nested="[
22-
{
23-
name: 'effectiveType',
24-
type: \"'slow-2g' | '2g' | '3g' | '4g' | undefined\",
25-
required: false,
26-
description: 'Connection quality indicator - undefined if API not supported',
27-
},
28-
{
29-
name: 'type',
30-
type: \"'bluetooth' | 'cellular' | 'ethernet' | 'mixed' | 'none' | 'other' | 'unknown' | 'wifi' | 'wimax' | undefined\",
31-
required: false,
32-
description: 'Physical connection type - undefined if API not supported',
33-
},
34-
{
35-
name: 'downlink',
36-
type: 'number | undefined',
37-
required: false,
38-
description: 'Downlink speed in Mbps - undefined if API not supported',
39-
},
40-
{
41-
name: 'rtt',
42-
type: 'number | undefined',
43-
required: false,
44-
description: 'Round-trip time in milliseconds - undefined if API not supported',
45-
},
46-
{
47-
name: 'saveData',
48-
type: 'boolean | undefined',
49-
required: false,
50-
description: \"User's data saver preference - undefined if API not supported\",
51-
},
52-
]"
14+
name=""
15+
type="NetworkStatus"
16+
description="status information"
17+
:nested="[
18+
{
19+
name: '',
20+
type: 'effectiveType',
21+
required: false,
22+
description:
23+
'Connection quality<br /> : \'slow-2g\' | \'2g\' | \'3g\' | \'4g\' - <code>type</code> - Physical connection<br /> : \'wifi\' | \'cellular\' | \'ethernet\' | etc. - <code>downlink</code> - Downlink speed in Mbps - <code>rtt</code> - Round-trip time in milliseconds - <code>saveData</code> - User\'s data saver preference.',
24+
},
25+
]"
5326
/>
5427

55-
## Examples
56-
57-
### Adaptive Image Quality
28+
## Example
5829

59-
```tsx
30+
````tsx
31+
```tsxp
6032
function AdaptiveImage() {
6133
const { effectiveType, saveData } = useNetworkStatus();
6234
6335
// Determine quality based on your app's needs
6436
const useHighQuality = effectiveType === '4g' && !saveData;
6537
6638
return (
67-
<img src={useHighQuality ? 'high-res.jpg' : 'low-res.jpg'} alt="Content" />
39+
<img
40+
src={useHighQuality ? 'high-res.jpg' : 'low-res.jpg'}
41+
alt="Content"
42+
/>
6843
);
6944
}
70-
```
71-
72-
### Conditional Video Autoplay
45+
````
7346
74-
```tsx
75-
function VideoPlayer() {
76-
const { type, downlink } = useNetworkStatus();
77-
78-
// Custom logic: only autoplay on wifi with good bandwidth
79-
const shouldAutoplay = type === 'wifi' && (downlink ?? 0) > 5;
80-
81-
return <video src="video.mp4" autoPlay={shouldAutoplay} />;
82-
}
8347
```
8448

85-
## Notes
86-
87-
### Browser Support
88-
89-
- **Chrome/Edge (Android)**: Full support for all properties
90-
- **Chrome/Edge (Desktop)**: Partial support (effectiveType, downlink, rtt, saveData available; type may be undefined)
91-
- **Firefox**: Not supported (all properties will be undefined)
92-
- **Safari**: Not supported (all properties will be undefined)
93-
94-
### SSR Safety
95-
96-
This hook is SSR-safe. It returns an empty object `{}` on the server and safely subscribes to network changes only in the browser environment.
97-
98-
### Usage Recommendations
99-
100-
1. Always check for undefined values before using them, as the API may not be supported in all browsers
101-
2. Provide fallback behavior for browsers that don't support the Network Information API
102-
3. Use the hook to enhance user experience, not as a required feature
103-
4. Consider combining `effectiveType` and `saveData` for optimal content delivery decisions
104-
105-
### References
106-
107-
- [Network Information API Specification](https://wicg.github.io/netinfo/)
108-
- [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API)
49+
```

packages/mobile/src/hooks/usePageVisibility/ko/usePageVisibility.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ description: '페이지가 현재 사용자에게 보이면 <code>true</code>',
2929
},
3030
{
3131
name: 'visibilityState',
32-
type: \"'visible' | 'hidden'\",
32+
type: &quot;'visible' | 'hidden'&quot;,
3333
required: false,
3434
description: '페이지의 현재 가시성 상태',
3535
},
Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# usePageVisibility
22

3-
React hook to detect page visibility changes.
4-
5-
Monitors when the user switches tabs or minimizes the browser using the Page Visibility API. This is useful for pausing/resuming animations, videos, or background tasks to improve performance and user experience.
6-
73
## Interface
84

95
```ts
@@ -12,36 +8,26 @@ function usePageVisibility(): PageVisibility;
128

139
### Parameters
1410

15-
This hook takes no parameters.
16-
1711
### Return Value
1812

1913
<Interface
20-
name=""
21-
type="PageVisibility"
22-
description="object with page visibility state."
23-
:nested="[
24-
{
25-
name: 'isVisible',
26-
type: 'boolean',
27-
required: false,
28-
description: '<code>true</code> if the page is currently visible to the user',
29-
},
30-
{
31-
name: 'visibilityState',
32-
type: \"'visible' | 'hidden'\",
33-
required: false,
34-
description: 'Current visibility state of the page',
35-
},
36-
]"
14+
name=""
15+
type="PageVisibility"
16+
description="visibility information"
17+
:nested="[
18+
{
19+
name: '',
20+
type: 'isVisible',
21+
required: false,
22+
description:
23+
'True if page is currently visible to the user - <code>visibilityState</code> - Current visibility state<br /> : \'visible\' | \'hidden\'.',
24+
},
25+
]"
3726
/>
3827

39-
## Examples
40-
41-
### Video Player Control
42-
43-
Automatically pause video playback when the user switches to another tab:
28+
## Example
4429

30+
````tsx
4531
```tsx
4632
function VideoPlayer() {
4733
const { isVisible } = usePageVisibility();
@@ -58,30 +44,8 @@ function VideoPlayer() {
5844
5945
return <video ref={videoRef} src="video.mp4" />;
6046
}
61-
```
62-
63-
### Analytics Tracking
64-
65-
Track when users leave or return to your page:
47+
````
6648
67-
```tsx
68-
function Analytics() {
69-
const { isVisible, visibilityState } = usePageVisibility();
70-
71-
useEffect(() => {
72-
if (visibilityState === 'hidden') {
73-
// Track when user leaves the page
74-
analytics.track('page_hidden');
75-
}
76-
}, [visibilityState]);
77-
78-
return null;
79-
}
8049
```
8150

82-
## Notes
83-
84-
- **SSR Safety**: During server-side rendering, this hook returns `{ isVisible: true, visibilityState: 'visible' }` as a safe default since the Page Visibility API is not available on the server.
85-
- **Browser Support**: The Page Visibility API is supported in all modern browsers. See [MDN Browser Compatibility](https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API#browser_compatibility) for details.
86-
- **Performance**: The hook uses the native `visibilitychange` event, which is highly optimized and has minimal performance impact.
87-
- **Visibility States**: The hook excludes the deprecated `'prerender'` state and only returns `'visible'` or `'hidden'`.
51+
```

packages/mobile/src/hooks/useScrollDirection/ko/useScrollDirection.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ description="스크롤 방향과 위치를 담은 객체예요."
3838
:nested="[
3939
{
4040
name: 'direction',
41-
type: \"'up' | 'down' | null\",
41+
type: &quot;'up' | 'down' | null&quot;,
4242
required: false,
4343
description: '현재 스크롤 방향. 초기 렌더링 시에는 <code>null</code>',
4444
},

0 commit comments

Comments
 (0)