31 lines
912 B
JavaScript
31 lines
912 B
JavaScript
import {useEffect, useState} from "react";
|
|
import {GET_TESTS_LIST} from "@/core/utils/routes";
|
|
import useRequest from "@/lib/hooks/useRequest";
|
|
|
|
const useTest = () => {
|
|
const requestServer = useRequest();
|
|
const [tests, setTests] = useState([]);
|
|
const [loadingTests, setLoadingTests] = useState(true);
|
|
const [errorTests, setErrorTests] = useState(null);
|
|
|
|
useEffect(() => {
|
|
const fetchTests = async () => {
|
|
try {
|
|
const response = await requestServer(`${GET_TESTS_LIST}`);
|
|
setTests(response.data.data);
|
|
setLoadingTests(false);
|
|
} catch (e) {
|
|
console.error("Error fetching tests types:", e);
|
|
setErrorTests(e);
|
|
setLoadingTests(false);
|
|
}
|
|
};
|
|
|
|
fetchTests();
|
|
}, []);
|
|
|
|
return {tests, loadingTests, errorTests};
|
|
};
|
|
|
|
export default useTest;
|