Coding task · Next.js course · Module 2: Routing and Layouts

Practice: Server Component with fetch

Server Components (the default in the App Router) render on the server - perfect for fetching data! They can be async. They CANNOT use useState, onClick, etc. The data is fetched before the HTML reaches the browser.

Task

Create an async Server Component (default export): export default async function ImplantsDashboard() { const implants = await fetch('https://api.example.com/implants').then(r => r.json()); return <ul>{implants.map(i => <li key={i.id}>{i.name}</li>)}</ul> }. On the server, fetch needs a full URL. No 'use client' = Server Component!