blob: b367811e205b035d627d84ce8e9a42315730a48d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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>
</>
);
}
|