()
| 27 | const { id } = useParams(); |
| 28 | const [blogPost, setBlogPost] = useState(null); |
| 29 | const fetchData = async () => { |
| 30 | try { |
| 31 | const response = await fetch(`${VITE_SERVER_PORT}/api/blog/getById/${id}`); |
| 32 | |
| 33 | const data = await response.json(); |
| 34 | setBlogPost(data.blog); // Set the retrieved blog post to state |
| 35 | } catch (error) { |
| 36 | console.error('Error fetching blog post:', error); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | useEffect(() => { |
| 41 | fetchData(); |