import { useEffect, useState } from "react"; import { QuizStatisticResponse, getStatistic } from "@root/api/quizStatistics"; import type { Moment } from "moment"; interface useQuizStatisticProps { to: Moment | null; from: Moment | null; } export function useQuizStatistic({ to, from }: useQuizStatisticProps) { const formatTo = to?.unix(); const formatFrom = from?.unix(); const [data, setData] = useState({ Registrations: 0, Quizes: 0, Results: 0, }); useEffect(() => { const requestStatistics = async () => { const [gottenData] = await getStatistic(Number(formatTo), Number(formatFrom)); if (gottenData) { setData(gottenData); } }; requestStatistics(); }, [formatTo, formatFrom]); return { ...data }; }