parent
ef02ddcf81
commit
37d041e917
1 changed files with 20 additions and 0 deletions
@ -0,0 +1,20 @@ |
|||||||
|
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; |
Loading…
Reference in new issue