File tree 1 file changed +10
-10
lines changed
1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -2,23 +2,23 @@ import { useEffect, useRef } from 'react'
2
2
3
3
export function usePollingEffect (
4
4
asyncCallback : any ,
5
- dependencies = [ ] ,
5
+ dependencies : any [ ] = [ ] ,
6
6
{
7
7
interval = 3000 , // 3 seconds,
8
- onCleanUp = ( ) => { } ,
8
+ onCleanUp = ( ) => { } ,
9
9
} = { }
10
10
) {
11
11
const timeoutIdRef = useRef < number | null > ( null )
12
12
useEffect ( ( ) => {
13
13
let _stopped = false
14
- ; ( async function pollingCallback ( ) {
15
- try {
16
- await asyncCallback ( )
17
- } finally {
18
- // Set timeout after it finished, unless stopped
19
- timeoutIdRef . current = ! _stopped && window . setTimeout ( pollingCallback , interval )
20
- }
21
- } ) ( )
14
+ ; ( async function pollingCallback ( ) {
15
+ try {
16
+ await asyncCallback ( )
17
+ } finally {
18
+ // Set timeout after it finished, unless stopped
19
+ timeoutIdRef . current = ! _stopped && window . setTimeout ( pollingCallback , interval )
20
+ }
21
+ } ) ( )
22
22
// Clean up if dependencies change
23
23
return ( ) => {
24
24
_stopped = true // prevent racing conditions
You can’t perform that action at this time.
0 commit comments