mirror of
https://git.roussel.pro/telecom-paris/pact.git
synced 2026-02-09 10:30:17 +01:00
26 lines
773 B
JavaScript
26 lines
773 B
JavaScript
import { useEffect, useState } 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 + `/borne/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};
|
|
} |