Preparing your workspace
Next.js can fetch data on the server, in client components when needed, or through application API boundaries depending on the use case.
Server-side data fetching is a powerful part of Next.js because server components can load data before rendering the UI. This can reduce client-side fetching code and keep server-only data access on trusted boundaries. Client-side fetching is still useful for highly interactive screens, live updates, or browser-driven data changes. The right approach depends on whether the data is public, user-specific, frequently changing, or tied to client interaction.
A public course page can load course information on the server, while a live notification panel can fetch or subscribe to updates on the client.
export default async function CoursesPage() {
const response = await fetch('https://example.com/api/courses');
if (!response.ok) {
throw new Error('Failed to load courses');
}
const courses = await response.json();
return (
<ul>
{courses.map((course: { id: string; title: string }) => (
<li key={course.id}>{course.title}</li>
))}
</ul>
);
}The page loads course data on the server and renders the returned courses.