import { getRecentPosts } from '@/lib/api';
export default async function RecentPosts() {
const posts = await getRecentPosts();
return (
<ul>
{posts.map((post) => (
<li key={post.id}>{post.title}</li>
))}
</ul>
);
}
'use client';
import { useState } from 'react';
export default function LikeButton({ postId }: { postId: string }) {
const [liked, setLiked] = useState(false);
const handleLike = async () => {
// Logic to send like to the server
setLiked(true);
};
return (
<button onClick={handleLike} disabled={liked}>
{liked ? 'Liked!' : 'Like'}
</button>
);
}
// Client Component
import LikeButton from '@/components/LikeButton';
// Could be Server or Client
import PostContent from '@/components/PostContent';
export default async function BlogPostPage(
{ params }: { params: { slug: string } })
{
const post = await getPostData(params.slug); // Fetch on Server
return (
<div>
{/* Data passed as prop */}
<PostContent content={post.content} />
{/* Data passed as prop */}
<LikeButton postId={post.id} />
</div>
);
}
// Client Component
import LikeButton from '@/components/LikeButton';
// Could be Server or Client
import PostContent from '@/components/PostContent';
export default async function BlogPostPage(
{ params }: { params: { slug: string } })
{
const post = await getPostData(params.slug); // Fetch on Server
return (
<div>
{/* Data passed as prop */}
<PostContent content={post.content} />
{/* ❌⚠️☢️ Will NOT WORK */}
<LikeButton postId={post.id} onClick={() => {}} />
</div>
);
}