From de9a9eac060974a7878f2bb5577f2b135596a555 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 22 Jul 2022 19:00:50 +0200 Subject: refactor(article): wrap useSWR with a custom hook to revalidate article --- src/utils/hooks/use-comments.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 cc9e560..f430f19 100644 --- a/src/utils/hooks/use-comments.tsx +++ b/src/utils/hooks/use-comments.tsx @@ -10,7 +10,8 @@ import useSWR from 'swr'; /** * Retrieve the comments of a page/article. - * @param contentId - A page/article id. + * + * @param {string | number} contentId - A page/article id. * @returns {Comment[]|undefined} */ const useComments = ( @@ -19,15 +20,14 @@ const useComments = ( ): Comment[] | undefined => { const { data } = useSWR( { api: getAPIUrl(), query: commentsQuery, variables: { contentId } }, - fetchAPI, - { fallback } + fetchAPI ); const comments = data?.comments.nodes.map((comment) => getCommentFromRawData(comment) ); - return comments ? buildCommentsTree(comments) : undefined; + return comments ? buildCommentsTree(comments) : fallback; }; export default useComments; -- cgit v1.2.3