mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-08-24 14:48:42 +08:00
Create usePolling custom hook
This commit is contained in:
11
ui/src/hooks/index.tsx
Normal file
11
ui/src/hooks/index.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
// usePolling repeatedly calls doFn with a fix time delay specified
|
||||
// by interval (in millisecond).
|
||||
export function usePolling(doFn: () => void, interval: number) {
|
||||
useEffect(() => {
|
||||
doFn();
|
||||
const id = setInterval(doFn, interval * 1000);
|
||||
return () => clearInterval(id);
|
||||
}, [interval, doFn]);
|
||||
}
|
Reference in New Issue
Block a user