mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Updated color selection. Added loading to fetch hook.
This commit is contained in:
parent
5524d504f4
commit
569fcc7f0b
7 changed files with 47 additions and 27 deletions
|
|
@ -7,6 +7,7 @@ export default function useFetch(url, params = {}, options = {}) {
|
|||
const dispatch = useDispatch();
|
||||
const [data, setData] = useState();
|
||||
const [error, setError] = useState();
|
||||
const [loading, setLoadiing] = useState(false);
|
||||
const keys = Object.keys(params)
|
||||
.sort()
|
||||
.map(key => params[key]);
|
||||
|
|
@ -14,6 +15,7 @@ export default function useFetch(url, params = {}, options = {}) {
|
|||
|
||||
async function loadData() {
|
||||
try {
|
||||
setLoadiing(true);
|
||||
setError(null);
|
||||
const time = performance.now();
|
||||
const data = await get(url, params);
|
||||
|
|
@ -25,6 +27,8 @@ export default function useFetch(url, params = {}, options = {}) {
|
|||
} catch (e) {
|
||||
console.error(e);
|
||||
setError(e);
|
||||
} finally {
|
||||
setLoadiing(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -42,5 +46,5 @@ export default function useFetch(url, params = {}, options = {}) {
|
|||
}
|
||||
}, [url, ...keys, ...update]);
|
||||
|
||||
return { data, error, loadData };
|
||||
return { data, error, loading, loadData };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue