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

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series πŸ“Ί

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series πŸ‘€

Watch the Youtube series

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay