aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/hooks/use-article.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/hooks/use-article.ts')
-rw-r--r--src/utils/hooks/use-article.ts35
1 files changed, 0 insertions, 35 deletions
diff --git a/src/utils/hooks/use-article.ts b/src/utils/hooks/use-article.ts
deleted file mode 100644
index 5e54ee4..0000000
--- a/src/utils/hooks/use-article.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import { useEffect, useState } from 'react';
-import useSWR from 'swr';
-import { convertPostToArticle, fetchPost } from '../../services/graphql';
-import type { Article, Maybe } from '../../types';
-
-export type UseArticleConfig = {
- /**
- * A fallback article
- */
- fallback?: Article;
- /**
- * The article slug
- */
- slug?: string;
-};
-
-/**
- * Retrieve an article by slug.
- *
- * @param {UseArticleConfig} config - The config.
- * @returns {Article|undefined} The matching article if it exists.
- */
-export const useArticle = ({
- slug,
- fallback,
-}: UseArticleConfig): Article | undefined => {
- const { data } = useSWR(slug, fetchPost, {});
- const [article, setArticle] = useState<Maybe<Article>>(fallback);
-
- useEffect(() => {
- if (data) convertPostToArticle(data).then((post) => setArticle(post));
- }, [data]);
-
- return article;
-};