From 37d041e917b8a0c0914bc765dc4b6e415dd3d113 Mon Sep 17 00:00:00 2001 From: Josue Date: Mon, 15 Mar 2021 18:05:51 -0400 Subject: [PATCH] refactor: modify fetcher to make it type agnostic --- striker-ui/lib/fetchers/periodicFetch.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 striker-ui/lib/fetchers/periodicFetch.ts 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;