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
726 B
25 lines
726 B
import useSWR, { SWRConfiguration } from 'swr'; |
|
|
|
import fetcher from './fetchJSON'; |
|
|
|
const periodicFetch = <T>( |
|
url: string, |
|
{ refreshInterval = 5000, onSuccess }: SWRConfiguration<T> = {}, |
|
): GetResponses<T> => { |
|
// 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: swrError } = useSWR<T>(url, fetcher, { |
|
refreshInterval, |
|
onSuccess, |
|
}); |
|
|
|
return { |
|
data, |
|
isLoading: !swrError && !data, |
|
error: swrError, |
|
}; |
|
}; |
|
|
|
export default periodicFetch;
|
|
|