Added the ability to view all exams
This commit is contained in:
19
src/hooks/useExams.tsx
Normal file
19
src/hooks/useExams.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
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);
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoading(true);
|
||||
axios
|
||||
.get<Exam[]>("/api/exam")
|
||||
.then((response) => setExams(response.data))
|
||||
.finally(() => setIsLoading(false));
|
||||
}, []);
|
||||
|
||||
return {exams, isLoading, isError};
|
||||
}
|
||||
Reference in New Issue
Block a user