mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Use next-basics package.
This commit is contained in:
parent
1a6af8fc41
commit
f4e0da481e
62 changed files with 255 additions and 373 deletions
|
|
@ -8,7 +8,7 @@ export default function useFetch(url, options = {}, update = []) {
|
|||
const [loading, setLoading] = useState(false);
|
||||
const [count, setCount] = useState(0);
|
||||
const { get } = useApi();
|
||||
const { params = {}, headers = {}, disabled, delay = 0, interval, onDataLoad } = options;
|
||||
const { params = {}, headers = {}, disabled = false, delay = 0, interval, onDataLoad } = options;
|
||||
|
||||
async function loadData(params) {
|
||||
try {
|
||||
|
|
@ -29,7 +29,9 @@ export default function useFetch(url, options = {}, update = []) {
|
|||
|
||||
onDataLoad?.(data);
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(e);
|
||||
|
||||
setError(e);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
|
@ -44,7 +46,7 @@ export default function useFetch(url, options = {}, update = []) {
|
|||
clearTimeout(id);
|
||||
};
|
||||
}
|
||||
}, [url, !!disabled, count, ...update]);
|
||||
}, [url, disabled, count, ...update]);
|
||||
|
||||
useEffect(() => {
|
||||
if (interval && !disabled) {
|
||||
|
|
@ -54,7 +56,7 @@ export default function useFetch(url, options = {}, update = []) {
|
|||
clearInterval(id);
|
||||
};
|
||||
}
|
||||
}, [interval, !!disabled]);
|
||||
}, [interval, disabled]);
|
||||
|
||||
return { ...response, error, loading };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue