hook stats

This commit is contained in:
2023-02-13 00:27:01 +01:00
parent 2d11036283
commit bd03a9d3e7
2 changed files with 43 additions and 16 deletions

View File

@@ -0,0 +1,26 @@
import { useEffect } from "react";
import { api } from "../config/reviewsApi";
export default function useStats(limit, interval) {
const [stats, setStats] = useState({});
const [loading, setLoading] = useState(true);
const [error, setError] = useState(false);
async function fetchData(limit, interval) {
const response = await fetch("http://" + api.HOST + `/get_stats?interval=${interval}&limit=${limit}`)
if(response.ok) {
const data = await response.json();
setStats(data);
setError(false);
}else {
setError(true)
}
setLoading(false);
}
useEffect(() => {
fetchData(limit, interval);
})
return {stats, loading, error};
}