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.
21 lines
371 B
21 lines
371 B
4 years ago
|
import useSWR from 'swr';
|
||
|
import fetcher from './fetchJSON';
|
||
|
|
||
|
const PeriodicFetch = <T>(
|
||
|
uuid: string,
|
||
|
uri: string,
|
||
|
refreshInterval = 2000,
|
||
|
): GetResponses => {
|
||
|
const { data, error } = useSWR<T>(`${uri}${uuid}`, fetcher, {
|
||
|
refreshInterval,
|
||
|
});
|
||
|
|
||
|
return {
|
||
|
data,
|
||
|
isLoading: !error && !data,
|
||
|
isError: error,
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export default PeriodicFetch;
|