DEV Community

Vaibhav Bhatia
Vaibhav Bhatia

Posted on

Understanding Server Components

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

Dynatrace image

Observability should elevate – not hinder – the developer experience.

Is your troubleshooting toolset diminishing code output? With Dynatrace, developers stay in flow while debugging – reducing downtime and getting back to building faster.

Explore Observability for Developers

Top comments (0)

Dev Diairies image

User Feedback & The Pivot That Saved The Project ↪️

We’re following the journey of a dev team building on the Stellar Network as they go from hackathon idea to funded startup, testing their product in the real world and adapting as they go.

Watch full video 🎥

👋 Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay