import { useEffect, useState } from "react"; import { Link, useParams } from "react-router-dom"; import { showPost } from "../services/postService"; export default function PostShow() { const {id} = useParams(); const [title, setTitle] = useState(""); const [body, setBody] = useState(""); const [loading, setLoading] = useState(true); useEffect(() => { if (id) { setLoading(true); showPost(Number(id)) .then(res => { console.log('Full response:', res); // Debug full response console.log('Response data:', res.data); // Debug data // Handle both response structures const post = res.data || res.data; setTitle(post.title || "No title"); setBody(post.body || "No body"); setLoading(false); }) .catch(err => { console.error('Error fetching post:', err); console.error('Error response:', err.response); setLoading(false); }); } }, [id]); return (
Loading...
) : ({title}
{body}