Create usePolling custom hook

This commit is contained in:
Ken Hibino
2020-11-29 15:04:24 -08:00
parent b9cb9211ce
commit 3dd6fdc0b0
10 changed files with 53 additions and 47 deletions

11
ui/src/hooks/index.tsx Normal file
View 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]);
}