File tree 1 file changed +7
-11
lines changed
packages/hooks/src/useRafTimeout
1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -46,24 +46,20 @@ function useRafTimeout(fn: () => void, delay: number | undefined) {
46
46
const fnRef = useLatest ( fn ) ;
47
47
const timerRef = useRef < Handle > ( ) ;
48
48
49
+ const clear = useCallback ( ( ) => {
50
+ if ( timerRef . current ) {
51
+ clearRafTimeout ( timerRef . current ) ;
52
+ }
53
+ } , [ ] ) ;
54
+
49
55
useEffect ( ( ) => {
50
56
if ( ! isNumber ( delay ) || delay < 0 ) return ;
51
57
timerRef . current = setRafTimeout ( ( ) => {
52
58
fnRef . current ( ) ;
53
59
} , delay ) ;
54
- return ( ) => {
55
- if ( timerRef . current ) {
56
- clearRafTimeout ( timerRef . current ) ;
57
- }
58
- } ;
60
+ return clear ;
59
61
} , [ delay ] ) ;
60
62
61
- const clear = useCallback ( ( ) => {
62
- if ( timerRef . current ) {
63
- clearRafTimeout ( timerRef . current ) ;
64
- }
65
- } , [ ] ) ;
66
-
67
63
return clear ;
68
64
}
69
65
You can’t perform that action at this time.
0 commit comments