| 1 |
import useSWR from 'swr' |
| 2 |
|
| 3 |
export const useFetch = (params, fetcher, options = {}) => { |
| 4 |
const { data: fetchedData, error } = useSWR(params, fetcher, { |
| 5 |
dedupingInterval: 60_000, |
| 6 |
refreshInterval: 0, |
| 7 |
...options, |
| 8 |
}) |
| 9 |
const data = fetchedData?.data ?? fetchedData |
| 10 |
return { data, loading: !data && !error, error } |
| 11 |
} |
| 12 |
|