@@ -3,7 +3,7 @@ import useLatest from '../useLatest';
3
3
import { isNumber } from '../utils' ;
4
4
5
5
interface Handle {
6
- id : number | NodeJS . Timer ;
6
+ id : number | ReturnType < typeof setInterval > ;
7
7
}
8
8
9
9
const setRafInterval = function ( callback : ( ) => void , delay : number = 0 ) : Handle {
@@ -12,23 +12,23 @@ const setRafInterval = function (callback: () => void, delay: number = 0): Handl
12
12
id : setInterval ( callback , delay ) ,
13
13
} ;
14
14
}
15
- let start = new Date ( ) . getTime ( ) ;
15
+ let start = Date . now ( ) ;
16
16
const handle : Handle = {
17
17
id : 0 ,
18
18
} ;
19
19
const loop = ( ) => {
20
- const current = new Date ( ) . getTime ( ) ;
20
+ const current = Date . now ( ) ;
21
21
if ( current - start >= delay ) {
22
22
callback ( ) ;
23
- start = new Date ( ) . getTime ( ) ;
23
+ start = Date . now ( ) ;
24
24
}
25
25
handle . id = requestAnimationFrame ( loop ) ;
26
26
} ;
27
27
handle . id = requestAnimationFrame ( loop ) ;
28
28
return handle ;
29
29
} ;
30
30
31
- function cancelAnimationFrameIsNotDefined ( t : any ) : t is NodeJS . Timer {
31
+ function cancelAnimationFrameIsNotDefined ( t : any ) : t is ReturnType < typeof setInterval > {
32
32
return typeof cancelAnimationFrame === typeof undefined ;
33
33
}
34
34
@@ -52,7 +52,9 @@ function useRafInterval(
52
52
const timerRef = useRef < Handle > ( ) ;
53
53
54
54
useEffect ( ( ) => {
55
- if ( ! isNumber ( delay ) || delay < 0 ) return ;
55
+ if ( ! isNumber ( delay ) || delay < 0 ) {
56
+ return ;
57
+ }
56
58
if ( immediate ) {
57
59
fnRef . current ( ) ;
58
60
}
0 commit comments