2021-12-19 07:30:16 -08:00
|
|
|
import { useEffect, useMemo } from "react";
|
|
|
|
|
import { useLocation } from "react-router-dom";
|
2020-11-29 15:04:24 -08:00
|
|
|
|
|
|
|
|
// 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]);
|
|
|
|
|
}
|
2021-12-19 07:30:16 -08:00
|
|
|
|
|
|
|
|
// useQuery gets the URL search params from the current URL.
|
|
|
|
|
export function useQuery(): URLSearchParams {
|
|
|
|
|
const { search } = useLocation();
|
|
|
|
|
return useMemo(() => new URLSearchParams(search), [search]);
|
|
|
|
|
}
|