File tree Expand file tree Collapse file tree 2 files changed +53
-1
lines changed Expand file tree Collapse file tree 2 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 10
10
"useSound" : " useSound" ,
11
11
"useTimer" : " useTimer" ,
12
12
"useToggle" : " useToggle" ,
13
- "useTranslation" : " useTranslation"
13
+ "useTranslation" : " useTranslation" ,
14
+ "useInterval" : " useInterval"
14
15
}
Original file line number Diff line number Diff line change
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
+ ```
You can’t perform that action at this time.
0 commit comments