💽 Server Component Fetching
Fetch data from React Server Components
import UserCard from '@/components/UserCard/UserCard';
import styles from './page.module.css';
import { prisma } from '@/lib/prisma';
export default async function Users() {
const users = await prisma.user.findMany();
return (
<div className={styles.grid}>
{users.map((user) => {
return <UserCard key={user.id} {...user} />;
})}
</div>
);
}
import Link from 'next/link';
import styles from './UserCard.module.css';
interface Props {
id: string;
name: string | null;
age: number | null;
image: string | null;
}
export default function UserCard({ id, name, age, image }: Props) {
return (
<div className={styles.card}>
<img
src={image ?? '/mememan.webp'}
alt={`${name}'s profile`}
className={styles.cardImage}
/>
<div className={styles.cardContent}>
<h3>
<Link href={`/users/${id}`}>{name}</Link>
</h3>
<p>Age: {age}</p>
</div>
</div>
);
}