mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Added useApi hook.
This commit is contained in:
parent
7bd49e6caf
commit
d19b6b5a82
22 changed files with 59 additions and 59 deletions
|
|
@ -1,14 +1,13 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { get } from 'lib/web';
|
||||
import { saveQuery } from 'store/queries';
|
||||
import useApi from './useApi';
|
||||
|
||||
export default function useFetch(url, options = {}, update = []) {
|
||||
const [response, setResponse] = useState();
|
||||
const [error, setError] = useState();
|
||||
const [loading, setLoadiing] = useState(false);
|
||||
const [count, setCount] = useState(0);
|
||||
const { basePath } = useRouter();
|
||||
const { get } = useApi();
|
||||
const { params = {}, headers = {}, disabled, delay = 0, interval, onDataLoad } = options;
|
||||
|
||||
async function loadData(params) {
|
||||
|
|
@ -17,7 +16,7 @@ export default function useFetch(url, options = {}, update = []) {
|
|||
setError(null);
|
||||
const time = performance.now();
|
||||
|
||||
const { data, status, ok } = await get(`${basePath}${url}`, params, headers);
|
||||
const { data, status, ok } = await get(url, params, headers);
|
||||
|
||||
await saveQuery(url, { time: performance.now() - time, completed: Date.now() });
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue