File tree Expand file tree Collapse file tree 1 file changed +10
-10
lines changed
Expand file tree Collapse file tree 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'
22
33export function usePollingEffect (
44 asyncCallback : any ,
5- dependencies = [ ] ,
5+ dependencies : any [ ] = [ ] ,
66 {
77 interval = 3000 , // 3 seconds,
8- onCleanUp = ( ) => { } ,
8+ onCleanUp = ( ) => { } ,
99 } = { }
1010) {
1111 const timeoutIdRef = useRef < number | null > ( null )
1212 useEffect ( ( ) => {
1313 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+ } ) ( )
2222 // Clean up if dependencies change
2323 return ( ) => {
2424 _stopped = true // prevent racing conditions
You can’t perform that action at this time.
0 commit comments