24 lines
637 B
TypeScript
24 lines
637 B
TypeScript
import {PaypalPayment} from "@/interfaces/paypal";
|
|
import axios from "axios";
|
|
import {useEffect, useState} from "react";
|
|
|
|
export default function usePaypalPayments() {
|
|
const [payments, setPayments] = useState<PaypalPayment[]>([]);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [isError, setIsError] = useState(false);
|
|
|
|
const getData = () => {
|
|
setIsLoading(true);
|
|
axios
|
|
.get<PaypalPayment[]>("/api/payments/paypal")
|
|
.then((response) => {
|
|
return setPayments(response.data);
|
|
})
|
|
.finally(() => setIsLoading(false));
|
|
};
|
|
|
|
useEffect(getData, []);
|
|
|
|
return {payments, isLoading, isError, reload: getData};
|
|
}
|