Skip to content

Commit 6476ac4

Browse files
committed
📝 docs: useInterval 문서 작성
1 parent 6a08eda commit 6476ac4

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

docs/pages/docs/hooks/_meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"useSound": "useSound",
1111
"useTimer": "useTimer",
1212
"useToggle": "useToggle",
13-
"useTranslation": "useTranslation"
13+
"useTranslation": "useTranslation",
14+
"useInterval": "useInterval"
1415
}

docs/pages/docs/hooks/useInterval.mdx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# useInterval
2+
3+
## Introduce
4+
5+
지정된 시간 간격만큼 반복적으로 콜백 함수를 호출하는 훅입니다.
6+
7+
```tsx
8+
const useInterval = (callback: () => void, ms: number): () => void
9+
```
10+
11+
- 지정된 시간 간격으로 콜백 함수를 호출하는 타이머를 설정합니다.
12+
- `ms` 값이 변경될 때마다 interval이 재설정되며, 컴포넌트가 언마운트될 때 자동으로 타이머가 정리됩니다.
13+
- 반환된 `clear` 함수를 호출하여 수동으로 타이머를 중지할 수도 있습니다.
14+
15+
### Props
16+
17+
- `callback` : 지정된 간격마다 호출될 콜백 함수
18+
- `ms` : 콜백 함수가 호출되는 시간 간격(밀리초)
19+
20+
### Returns
21+
22+
- interval 중지 함수
23+
24+
## Examples
25+
26+
```tsx copy filename="TestComponent.tsx"
27+
function TestComponent() {
28+
const [count, setCount] = useState(0);
29+
const [delay, setDelay] = useState(1000);
30+
31+
const clear = useInterval(() => {
32+
setCount(count + 1);
33+
}, delay);
34+
35+
const handleStop = () => {
36+
clear();
37+
};
38+
39+
const handleDelay = ({ target }) => {
40+
setDelay(target.value);
41+
};
42+
43+
return (
44+
<div>
45+
<input type="number" value={delay} onChange={handleDelay} />
46+
<button onClick={handleStop}>stop</button>
47+
<div>{count}</div>
48+
</div>
49+
);
50+
}
51+
```

0 commit comments

Comments
 (0)