Understanding Server Components
Vaibhav Bhatia

Vaibhav Bhatia @vaibhav_bhatia

About: I am a passionate computer engineer. In these blogs I share my experience on web technologies Other blogs I recommend are - OverReacted by Dan Abramov https://kentcdodds.com/

Location:
New Delhi, India
Joined:
Feb 8, 2025

Understanding Server Components

Publish Date: Feb 7
0 0

Server Components: The New Default

Server Components are the default in Next.js 13+ and represent a fundamental shift in how we write React code. They run exclusively on the server and help reduce the JavaScript bundle sent to the client.

Key Benefits of Server Components

  1. Reduced Bundle Size: Since they run on the server, their code is never sent to the client 2.** Direct Backend Access**: Can directly query databases and access backend resources
  2. Improved Initial Page Load: No client-side JavaScript overhead
  3. Better Security: Sensitive data remains on the server

Example of a Server Component

// app/users/page.js
async function UsersPage() {
  // Direct database query - only possible in server components
  const users = await db.query('SELECT * FROM users');

  return (
    <div className="p-4">
      <h1>Users List</h1>
      {users.map(user => (
        <div key={user.id} className="mb-2">
          {user.name} - {user.email}
        </div>
      ))}
    </div>
  );
}

export default UsersPage;
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment