Added packages for students to be able to purchase
This commit is contained in:
22
src/hooks/usePackages.tsx
Normal file
22
src/hooks/usePackages.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
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};
|
||||
}
|
||||
Reference in New Issue
Block a user