import { notFound } from "next/navigation";
import { useToast } from "@/app/components/ui/ToastProvider";
import { useEffect } from "react";
export default async function PostDetail({ params }: { params: { id: string } }) {
const res = await fetch(`${process.env.NEXT_PUBLIC_BASE_URL ?? ""}/api/posts/${params.id}`, { cache: "no-store" });
if (!res.ok) return notFound();
const { post } = await res.json();
return (
);
}
function ClientPostDetail({ post }: { post: { id: string; title: string; content: string } }) {
// client only
// @ts-expect-error react client hook use
const { show } = useToast();
// @ts-expect-error react client hook use
useEffect(() => {
fetch(`/api/posts/${post.id}/view`, { method: "POST" });
}, [post.id]);
return (
{post.title}
{post.content}
);
}