CodShot
TSX Public

Parallel Data Fetching in a Server Component

Start independent server requests together to reduce total rendering time.

#nextjs #server-components #async #performance
TSX
// app/dashboard/page.tsx

async function getUser() {
  return db.user.findFirst();
}

async function getRecentOrders() {
  return db.order.findMany({
    orderBy: {
      createdAt: 'desc',
    },
    take: 5,
  });
}

export default async function DashboardPage() {
  const userPromise = getUser();
  const ordersPromise = getRecentOrders();

  const [user, orders] = await Promise.all([
    userPromise,
    ordersPromise,
  ]);

  return (
    <main>
      <h1>Welcome, {user?.name ?? 'Guest'}</h1>

      <ul>
        {orders.map((order) => (
          <li key={order.id}>
            Order {order.id}
          </li>
        ))}
      </ul>
    </main>
  );
}

Snippet actions

CodShot user
CodShot user
Updated: 2026-08-06 18:36
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support