diff --git a/striker-ui/lib/fetchers/periodicFetch.ts b/striker-ui/lib/fetchers/periodicFetch.ts new file mode 100644 index 00000000..e6093b0f --- /dev/null +++ b/striker-ui/lib/fetchers/periodicFetch.ts @@ -0,0 +1,20 @@ +import useSWR from 'swr'; +import fetcher from './fetchJSON'; + +const PeriodicFetch = ( + uuid: string, + uri: string, + refreshInterval = 2000, +): GetResponses => { + const { data, error } = useSWR(`${uri}${uuid}`, fetcher, { + refreshInterval, + }); + + return { + data, + isLoading: !error && !data, + isError: error, + }; +}; + +export default PeriodicFetch;