frontPanel/src/utils/hooks/useAnalytics.ts

31 lines
861 B
TypeScript

import { getGeneral, getDevices, getQuestions } from "@api/statistic";
import { useEffect, useState } from "react";
interface Props {
quizId: string;
to: number;
from: number;
}
export function useAnalytics({
quizId,
to,
from,
}: Props) {
const [devices, setDevices] = useState();
const [general, setGeneral] = useState();
const [questions, setQuestions] = useState();
useEffect(() => {
(async () => {
const gottenGeneral = await getGeneral(quizId, to, from)
const gottenDevices = await getDevices(quizId, to, from)
const gottenQuestions = await getQuestions(quizId, to, from)
setDevices(gottenGeneral)
setGeneral(gottenDevices)
setQuestions(gottenQuestions)
})()
}, [to, from]);
return { devices, general, questions };
}