diff options
Diffstat (limited to 'frontend/src/pages/articles/Article.tsx')
| -rw-r--r-- | frontend/src/pages/articles/Article.tsx | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/frontend/src/pages/articles/Article.tsx b/frontend/src/pages/articles/Article.tsx index b367811..1a96ada 100644 --- a/frontend/src/pages/articles/Article.tsx +++ b/frontend/src/pages/articles/Article.tsx @@ -1,25 +1,35 @@ import { useState, useEffect } from "react"; import { useParams } from "react-router-dom"; -export default function Article () { - const { id } = useParams(); - const [articleData, setArticleData] = useState<any>(); +type article = { + id: number; + title: string; + photoUrl: string; + content: string; + createdOn: string; + updateOn: string; +}; - useEffect(() => { - const url = `${import.meta.env.VITE_API_TITLE}/api/v1/article/${id}`; - fetch(url).then((response) => { - if (response.ok) { - return response.json(); - } - throw new Error("Network response was not ok."); - }).then((response) => setArticleData(response)); //.catch(() => navigate("/")); - }, [id]); +export default function Article() { + const { id } = useParams(); + const [articleData, setArticleData] = useState<article>(); - return( - <> - <h1>{articleData?.title}</h1> - <div>{articleData?.content}</div> - </> - ); + useEffect(() => { + const url = `${import.meta.env.VITE_API_TITLE}/api/v1/article/${id}`; + fetch(url) + .then((response) => { + if (response.ok) { + return response.json(); + } + throw new Error("Network response was not ok."); + }) + .then((response) => setArticleData(response)); //.catch(() => navigate("/")); + }, [id]); + return ( + <> + <h1>{articleData?.title}</h1> + <div>{articleData?.content}</div> + </> + ); } |
