github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/hooks/index.tsx (about) 1 import { useEffect, useMemo } from "react"; 2 import { useLocation } from "react-router-dom"; 3 4 // usePolling repeatedly calls doFn with a fix time delay specified 5 // by interval (in millisecond). 6 export function usePolling(doFn: () => void, interval: number) { 7 useEffect(() => { 8 doFn(); 9 const id = setInterval(doFn, interval * 1000); 10 return () => clearInterval(id); 11 }, [interval, doFn]); 12 } 13 14 // useQuery gets the URL search params from the current URL. 15 export function useQuery(): URLSearchParams { 16 const { search } = useLocation(); 17 return useMemo(() => new URLSearchParams(search), [search]); 18 }