Local modifications to ClusterLabs/Anvil by Alteeve
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

25 lines
706 B

import useSWR, { SWRConfiguration } from 'swr';
import fetcher from './fetchJSON';
const periodicFetch = <T>(
url: string,
{ refreshInterval = 5000, onSuccess }: SWRConfiguration = {},
): GetResponses => {
// The purpose of react-hooks/rules-of-hooks is to ensure that react hooks
// are called in order (i.e., not potentially skipped due to conditionals).
// We can safely disable this rule as this function is simply a wrapper.
// eslint-disable-next-line react-hooks/rules-of-hooks
const { data, error } = useSWR<T>(url, fetcher, {
refreshInterval,
onSuccess,
});
return {
data,
isLoading: !error && !data,
isError: error,
};
};
export default periodicFetch;