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
- 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
- Improved Initial Page Load: No client-side JavaScript overhead
- 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;
Top comments (0)