File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed
packages/hooks/src/useRafInterval Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,12 @@ function useRafInterval(
51
51
const fnRef = useLatest ( fn ) ;
52
52
const timerRef = useRef < Handle > ( ) ;
53
53
54
+ const clear = useCallback ( ( ) => {
55
+ if ( timerRef . current ) {
56
+ clearRafInterval ( timerRef . current ) ;
57
+ }
58
+ } , [ ] ) ;
59
+
54
60
useEffect ( ( ) => {
55
61
if ( ! isNumber ( delay ) || delay < 0 ) {
56
62
return ;
@@ -61,19 +67,9 @@ function useRafInterval(
61
67
timerRef . current = setRafInterval ( ( ) => {
62
68
fnRef . current ( ) ;
63
69
} , delay ) ;
64
- return ( ) => {
65
- if ( timerRef . current ) {
66
- clearRafInterval ( timerRef . current ) ;
67
- }
68
- } ;
70
+ return clear ;
69
71
} , [ delay ] ) ;
70
72
71
- const clear = useCallback ( ( ) => {
72
- if ( timerRef . current ) {
73
- clearRafInterval ( timerRef . current ) ;
74
- }
75
- } , [ ] ) ;
76
-
77
73
return clear ;
78
74
}
79
75
You can’t perform that action at this time.
0 commit comments