From b3c5e62257ec2c7ee1ff8459eb439e5607b2106c Mon Sep 17 00:00:00 2001 From: G Date: Wed, 29 May 2024 17:08:23 +0000 Subject: [PATCH] custom hook for transaction history --- src/hooks/useTransactionsHistory.tsx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/hooks/useTransactionsHistory.tsx diff --git a/src/hooks/useTransactionsHistory.tsx b/src/hooks/useTransactionsHistory.tsx new file mode 100644 index 0000000..43245e0 --- /dev/null +++ b/src/hooks/useTransactionsHistory.tsx @@ -0,0 +1,26 @@ +import { type Transaction, getTransactionsHistory } from "@/utils/requests/transactions"; +import { LOG } from "@logger"; +import { useQuery } from "@tanstack/react-query"; +import { useMemo } from "react"; + +const log = LOG.extend("useTransactionsHistory"); + +const useTransactionsHistory = () => { + log.verbose("useTransactionsHistory"); + + const { data, isLoading, error, refetch } = useQuery({ + queryKey: ["transactionsHistory"], + queryFn: getTransactionsHistory, + }); + + const transactionsHistory: Transaction[] = useMemo(() => data || [], [data]); + + return { + transactionsHistory, + isLoading, + error, + refetch, + }; +}; + +export default useTransactionsHistory; -- libgit2 0.27.1