From baac7d6eeaf522ff5faa28906cb1200e60a19c07 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Sat, 23 Jul 2022 15:31:45 +0200
Subject: fix(article): prevent TypeError on build

By switching to custom hooks for revalidating articles and comments,
everything was working on development mode but articles failed to build
for production.
---
 src/utils/hooks/use-comments.tsx | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

(limited to 'src/utils/hooks/use-comments.tsx')

diff --git a/src/utils/hooks/use-comments.tsx b/src/utils/hooks/use-comments.tsx
index f430f19..9076888 100644
--- a/src/utils/hooks/use-comments.tsx
+++ b/src/utils/hooks/use-comments.tsx
@@ -8,18 +8,25 @@ import { Comment } from '@ts/types/app';
 import { RawComment } from '@ts/types/raw-data';
 import useSWR from 'swr';
 
+export type UseCommentsConfig = {
+  contentId?: string | number;
+  fallback?: Comment[];
+};
+
 /**
  * Retrieve the comments of a page/article.
  *
  * @param {string | number} contentId - A page/article id.
  * @returns {Comment[]|undefined}
  */
-const useComments = (
-  contentId: string | number,
-  fallback?: Comment[]
-): Comment[] | undefined => {
+const useComments = ({
+  contentId,
+  fallback,
+}: UseCommentsConfig): Comment[] | undefined => {
   const { data } = useSWR(
-    { api: getAPIUrl(), query: commentsQuery, variables: { contentId } },
+    contentId
+      ? { api: getAPIUrl(), query: commentsQuery, variables: { contentId } }
+      : null,
     fetchAPI<RawComment, typeof commentsQuery>
   );
 
-- 
cgit v1.2.3

