anvil/striker-ui/lib/fetchers/periodicFetch.ts
2021-06-04 12:11:49 -04:00

19 lines
342 B
TypeScript

import useSWR from 'swr';
import fetcher from './fetchJSON';
const PeriodicFetch = <T>(
url: string,
refreshInterval = 5000,
): GetResponses => {
const { data, error } = useSWR<T>(url, fetcher, {
refreshInterval,
});
return {
data,
isLoading: !error && !data,
isError: error,
};
};
export default PeriodicFetch;