From 3f45976b73ba4a7b273bf7b7871820a7d3836dc8 Mon Sep 17 00:00:00 2001
From: Lukas <lukas.budginas@gmail.com>
Date: Thu, 28 Nov 2024 19:27:47 +0200
Subject: [PATCH] Create custom hook to fetch post content data

---
 hooks/api/postPage/usePostContent.tsx | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
 create mode 100644 hooks/api/postPage/usePostContent.tsx

diff --git a/hooks/api/postPage/usePostContent.tsx b/hooks/api/postPage/usePostContent.tsx
new file mode 100644
index 00000000..f91330fc
--- /dev/null
+++ b/hooks/api/postPage/usePostContent.tsx
@@ -0,0 +1,23 @@
+import { useQuery } from "@tanstack/react-query";
+import fetchingService from "@/services/FetchingService";
+
+const usePostContent = (accountName: string, permlink: string) => {
+  const trimAccount = accountName.replace("@", "");
+
+  const { data, isLoading, isError } = useQuery({
+    queryKey: ["blockSearch", trimAccount, permlink],
+    queryFn: () => fetchPostContent(trimAccount, permlink),
+    refetchOnWindowFocus: false,
+  });
+
+  const fetchPostContent = async (accountName: string, permlink: string) => {
+    if (!accountName || !permlink) return null;
+
+    const response = await fetchingService.getContent(accountName, permlink);
+    return response;
+  };
+
+  return { data, isLoading, isError };
+};
+
+export default usePostContent;
-- 
GitLab