| 1 |
import useSWR from 'swr'; |
| 2 |
|
| 3 |
export const useFetch = (params, fetcher, options = {}) => { |
| 4 |
const { data, error } = useSWR(params, (key) => fetcher(key), { |
| 5 |
revalidateIfStale: false, |
| 6 |
revalidateOnFocus: false, |
| 7 |
revalidateOnReconnect: false, |
| 8 |
...options, |
| 9 |
}); |
| 10 |
|
| 11 |
return { |
| 12 |
data, |
| 13 |
loading: !data && !error && !error?.message, |
| 14 |
error, |
| 15 |
}; |
| 16 |
}; |
| 17 |
|