19 lines
342 B
TypeScript
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;
|