mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Updated polling logic.
This commit is contained in:
parent
fdc92d087b
commit
9737127bb1
6 changed files with 33 additions and 19 deletions
|
|
@ -11,10 +11,7 @@ export default function useFetch(url, params = {}, options = {}) {
|
|||
const [error, setError] = useState();
|
||||
const [loading, setLoadiing] = useState(false);
|
||||
const { basePath } = useRouter();
|
||||
const keys = Object.keys(params)
|
||||
.sort()
|
||||
.map(key => params[key]);
|
||||
const { update = [], onDataLoad = () => {}, disabled, headers } = options;
|
||||
const { update = [], onDataLoad = () => {}, disabled, headers, interval, delay = 0 } = options;
|
||||
|
||||
async function loadData() {
|
||||
try {
|
||||
|
|
@ -43,10 +40,11 @@ export default function useFetch(url, params = {}, options = {}) {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
console.log('effect', params);
|
||||
if (url && !disabled) {
|
||||
const { interval, delay = 0 } = options;
|
||||
|
||||
setTimeout(() => loadData(), delay);
|
||||
if (!data) {
|
||||
setTimeout(() => loadData(), delay);
|
||||
}
|
||||
|
||||
const id = interval ? setInterval(() => loadData(), interval) : null;
|
||||
|
||||
|
|
@ -54,7 +52,7 @@ export default function useFetch(url, params = {}, options = {}) {
|
|||
clearInterval(id);
|
||||
};
|
||||
}
|
||||
}, [url, disabled, ...keys, ...update]);
|
||||
}, [data, url, disabled, ...update]);
|
||||
|
||||
return { data, status, error, loading };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue