Why Server Components Are the Default in Next.js
📖 Scenario: You are building a simple Next.js app that shows a greeting message and the current date and time. You want to understand why Next.js uses server components by default to improve performance and user experience.
🎯 Goal: Create a Next.js app with a server component that renders a greeting and the current date/time on the server, then add a client component that updates the time every second. This will show how server components handle static content by default and client components handle dynamic updates.
📋 What You'll Learn
Create a server component named
Greeting that displays a greeting message and the current date/time.Create a client component named
Clock that updates the time every second.Use the
use client directive in the client component.Render the
Greeting component in the main page and include the Clock component inside it.Ensure the server component fetches the date/time only once on the server.
Ensure the client component updates the time dynamically on the browser.
💡 Why This Matters
🌍 Real World
Many modern web apps use server components to improve performance by sending pre-rendered HTML and only loading JavaScript when needed for interactivity.
💼 Career
Understanding server and client components in Next.js is essential for building fast, scalable React apps and is a key skill for frontend and full-stack developers.
Progress0 / 4 steps