diff options
| author | realtradam <[email protected]> | 2024-07-24 23:15:03 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2024-07-24 23:15:03 -0400 |
| commit | 054e25bb66269d1d99ee0b0afa3b26abee2db80f (patch) | |
| tree | 0333ca0d25a9c435addd3e0e99518dd578f814d4 /frontend/src/pages/Article.tsx | |
| parent | e36832834564f401622ef293c19fc778ab43f9ae (diff) | |
| download | spring-blog-054e25bb66269d1d99ee0b0afa3b26abee2db80f.tar.gz spring-blog-054e25bb66269d1d99ee0b0afa3b26abee2db80f.zip | |
port api endpoints to json and add react pages to interact with them
Diffstat (limited to 'frontend/src/pages/Article.tsx')
| -rw-r--r-- | frontend/src/pages/Article.tsx | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/frontend/src/pages/Article.tsx b/frontend/src/pages/Article.tsx new file mode 100644 index 0000000..b367811 --- /dev/null +++ b/frontend/src/pages/Article.tsx @@ -0,0 +1,25 @@ +import { useState, useEffect } from "react"; +import { useParams } from "react-router-dom"; + +export default function Article () { + const { id } = useParams(); + const [articleData, setArticleData] = useState<any>(); + + 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> + </> + ); + +} |
