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