// page.tsx
"use client";
import { useQuery } from "@tanstack/react-query";
import { getPosts } from "./actions";
export default function Home() {
const { data, error, isLoading } = useQuery({
queryKey: ["posts"],
queryFn: getPosts,
});
return error ? (
<div>Oops, an error</div>
) : isLoading ? (
<div>Loading...</div>
) : (
<ul>
{data.map((post) => (
<li key={post.id}>{post.name}</li>
))}
</ul>
);
}
// page.tsx
"use client";
import { useQuery } from "@tanstack/react-query";
import { getPosts } from "./actions";
export default function Home() {
const { data, error, isLoading } = useQuery({
queryKey: ["posts"],
queryFn: getPosts,
});
return error ? (
<div>Oops, an error</div>
) : isLoading ? (
<div>Loading...</div>
) : (
<ul>
{data.map((post) => (
<li key={post.id}>{post.name}</li>
))}
</ul>
);
}