'use client'; import { useQuery } from '@tanstack/react-query'; type Post = { id: number; title: string; body: string; userId: number; }; async function fetchPosts(): Promise { const response = await fetch('https://jsonplaceholder.typicode.com/posts'); if (!response.ok) { throw new Error('Failed to fetch posts'); } return response.json(); } type PostsListProps = { initialData?: Post[]; }; export function PostsList({ initialData }: PostsListProps) { const { data: posts, isLoading, error, refetch } = useQuery({ queryKey: ['posts'], queryFn: fetchPosts, initialData, }); if (isLoading) { return
Loading posts...
; } if (error) { return (
Error: {' '} {error.message}
); } return (

Posts

{posts?.slice(0, 5).map(post => (

{post.title}

{post.body}

))}
); }