22 lines
557 B
TypeScript
22 lines
557 B
TypeScript
import {Exam} from "@/interfaces/exam";
|
|
import axios from "axios";
|
|
import {useEffect, useState} from "react";
|
|
|
|
export default function useExams() {
|
|
const [exams, setExams] = useState<Exam[]>([]);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [isError, setIsError] = useState(false);
|
|
|
|
const getData = () => {
|
|
setIsLoading(true);
|
|
axios
|
|
.get<Exam[]>("/api/exam")
|
|
.then((response) => setExams(response.data))
|
|
.finally(() => setIsLoading(false));
|
|
};
|
|
|
|
useEffect(getData, []);
|
|
|
|
return {exams, isLoading, isError, reload: getData};
|
|
}
|