mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-10-23 23:06:11 +08:00
12 lines
347 B
TypeScript
12 lines
347 B
TypeScript
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]);
|
|
}
|