React and Next.js have introduced powerful new capabilities to enhance performance and scalability in modern web applications. One of the most notable features is React Server Components (RSC), which enable rendering parts of your UI on the serverβreducing client-side JavaScript and improving load times.
In this guide, weβll explore how RSC works in Next.js 15 by building a practical GitHub User Explorer app. Youβll learn how to separate server and client logic, fetch data efficiently, and apply clean UI patternsβall in a way thatβs beginner-friendly and perfect for strengthening your portfolio.
π§ Note: This post is written for beginners trying out React Server Components for the first time, especially in the context of Next.js 15.
π Table of Contents
- Introduction to React Server Components
- Visualizing Server vs Client Components
- Project Architecture & Tech Stack
- Server-Side Data Fetching
- Client Components for Interactive UI
- Connecting Server and Client Logic
- Styling with Tailwind CSS
- Doβs and Donβts of Server Components
- Best Practices & Patterns
- Demo
- Running the Demo Locally
- Enhancements & Practice Tips
- Published App & Resources
- Conclusion
Introduction to React Server Components βοΈ
React Server Components (RSC) allow you to fetch, process, and render UI on the server, delivering only HTML to the client. The client gets a minimal JavaScript bundle, keeps sensitive logic secure, and improves performance. In Next.js 15, RSC is built into the App Router, making server-client composability seamless.
Key Advantages
- π Performance: Smaller bundles, faster loads
- π Security: API keys/logic stay server-side
- π§Ή Clean Code Separation: Server for data, client for interactivity
Visualizing Server vs Client Components
Understanding the difference between Server Components and Client Components is crucial when working with Next.js 15 and React Server Components (RSC). Hereβs a simple visual to help clarify:
βββββββββββββββββββββββββββββββ
β Server Component β
βββββββββββββββββββββββββββββββ€
β β
Runs on the server β
β β
Can access backend APIs β
β β
Can query the database β
β β
No JS sent to browser β
β β Cannot use hook(useState)β
βββββββββββββββββββββββββββββββ
β
Passes HTML only
β
βββββββββββββββββββββββββββββββ
β Client Component β
βββββββββββββββββββββββββββββββ€
β β
Runs in the browser β
β β
Can use useState, events β
β β
Supports interactivity β
β β Cannot access backend β
βββββββββββββββββββββββββββββββ
Project Architecture & Tech Stack π οΈ
Our GitHub User Explorer lets you:
- π Enter a GitHub username
- π Fetch the user's profile and public repositories from GitHubβs official API
- π οΈ Interactively filter repositories by language
Stack Breakdown:
| Technology | Purpose |
|---|---|
| Next.js 15 | First-class RSC support, React framework |
| React | Modern component-based UI |
| Tailwind CSS | Utility-first, mobile-friendly styling |
| GitHub API | Real-time profiles and repository data |
| ESLint, Prettier | Format and code-quality automation |
| Husky, Lint-Staged | Pre-commit code safety |
Server-Side Data Fetching ποΈ
The main server component (page.tsx) fetches both user info and the list of public repos, handling responses and errors for a smooth experience.
// This is a React Server Component in Next.js 15
// It fetches GitHub user details and their repositories on the server side
import { GitHubUser, Repo } from '../types';
import RepoListClient from './Components/RepoListClient';
// Base URL for GitHub API
const GITUSERURL = `https://api.github.com/users`;
export default async function UserPage({
params,
}: {
params: Promise<{ username: string }>;
}) {
// Await the route params β username is dynamic
const { username } = await params;
// Fetch user and repos in parallel for better performance
const [userRes, repoRes] = await Promise.all([
fetch(`${GITUSERURL}/${username}`), // Fetch user details
fetch(`${GITUSERURL}/${username}/repos`, {
// Fetch user repositories with revalidation every 60s
next: { revalidate: 60 },
}),
]);
// If the user is not found, show a fallback UI
if (!userRes.ok) {
return <div className="p-4">User not found</div>;
}
// Parse the responses as JSON
const user: GitHubUser = await userRes.json();
const repos: Repo[] = repoRes.ok ? await repoRes.json() : [];
return (
<div className="space-y-6 p-6">
{/* User profile section */}
<div className="flex items-center gap-4">
<img
src={user.avatar_url}
alt={user.login}
className="w-20 rounded-full"
/>
<div>
<h2 className="text-xl">{user.name}</h2>
<p className="text-gray-600">@{user.login}</p>
<p>{user.bio}</p>
</div>
</div>
{/* Client component to render repo list */}
<RepoListClient repos={repos} />
</div>
);
}
- π Concurrent Fetching: Profile & repos load in parallel
- β‘ Optimized Data: Revalidates every 60 seconds
- π« User Feedback: βUser not foundβ for invalid usernames
Client Components for Interactive UI ποΈ
RSC handle server data, but your app also needs interactivityβthe job of client components.
RepoListClient.tsx
RepoListClient.tsx is a Client Component that conditionally renders a filterable list of repositories. It uses the RepoFilter component internally and gracefully handles the case when no public repositories exist.
'use client'; // This is a Client Component since it uses interactivity via RepoFilter
import { Repo } from '../../types';
import RepoFilter from './RepoFilter';
// This component displays the user's public GitHub repositories with filtering
export default function RepoListClient({ repos }: { repos: Repo[] }) {
// Handle case when user has no public repositories
if (!repos || repos.length === 0) {
return (
<div className="text-gray-700 dark:text-gray-300">
This user has no public repositories.
</div>
);
}
return (
<div className="mt-6">
{/* Section heading */}
<h2 className="mb-2 text-xl font-semibold text-black dark:text-white">
Public Repositories
</h2>
{/* Render the RepoFilter component to allow filtering by language */}
<RepoFilter repos={repos} />
</div>
);
}
RepoFilter.tsx
Lets users filter repositories by language with instant updates.
'use client'; // Mark this as a Client Component
import { useState } from 'react';
import { Repo } from '../../types';
// A filterable list of GitHub repositories based on programming language
export default function RepoFilter({ repos }: { repos: Repo[] }) {
// State to track selected language for filtering
const [selectedLang, setSelectedLang] = useState('All');
// Get unique list of languages from repo data
const languages = Array.from(
new Set(repos.map((repo) => repo.language).filter(Boolean)) // Filter out null/undefined
);
// Apply filtering logic
const filteredRepos =
selectedLang === 'All'
? repos // Show all repos if "All" is selected
: repos.filter((repo) => repo.language === selectedLang); // Filter by selected language
return (
<div>
{/* Language filter buttons */}
<div className="mb-4 flex flex-wrap gap-2">
<button
onClick={() => setSelectedLang('All')}
className={`rounded px-3 py-1 ${
selectedLang === 'All'
? 'bg-blue-600 text-white' // Highlight selected
: 'bg-gray-200 dark:bg-gray-700 dark:text-white'
}`}
>
All
</button>
{/* Render a button for each unique language */}
{languages.map((lang) => (
<button
key={lang}
onClick={() => setSelectedLang(lang)}
className={`rounded px-3 py-1 ${
selectedLang === lang
? 'bg-blue-600 text-white'
: 'bg-gray-200 dark:bg-gray-700 dark:text-white'
}`}
>
{lang}
</button>
))}
</div>
{/* Filtered repo list */}
<ul className="space-y-4">
{filteredRepos.map((repo) => (
<li
key={repo.id}
className="rounded border border-gray-300 bg-white p-4 text-black dark:border-gray-700 dark:bg-gray-800 dark:text-white"
>
{/* Repo name linking to GitHub */}
<a
href={repo.html_url}
target="_blank"
rel="noopener noreferrer"
className="font-semibold text-blue-600 dark:text-blue-400"
>
{repo.name}
</a>
{/* Description */}
<p className="text-sm text-gray-600 dark:text-gray-300">
{repo.description || 'No description'}
</p>
{/* Programming language tag */}
<span className="rounded bg-gray-200 px-2 py-1 text-sm dark:bg-gray-700">
{repo.language || 'Unknown'}
</span>
</li>
))}
</ul>
</div>
);
}
- π§ Dynamic Filter: Only shows languages found in user repos
- β‘ Instant UI: Filtering updates instantly, no extra fetches!
Connecting Server and Client Logic π
- π Data fetched server-side is passed as props to the client component tree.
- ποΈ Client components handle interactivity without further server or API calls.
- π Sensitive API logic always stays on the server.
Styling with Tailwind CSS π¨
Tailwind CSS provides a responsive, visually appealing, and maintainable UI:
- π¨ Modern design with utility classes (borders, spacing, colors)
- π± Responsive for both desktop and mobile
- π Instant dark mode support
Doβs and Donβts of Server Components
To use React Server Components effectively in Next.js 15, follow these best practices:
Doβs
β
Use async/await to fetch data directly in the component
β
Access backend services like databases, APIs, or secret environment variables
β
Keep the components stateless and pure
β
Import and compose other Server Components
β
Use next: { revalidate: 60 } for caching and revalidation
Donβts
β Donβt use hooks like useState, useEffect, or useContext
β Donβt access browser APIs like window, localStorage, or navigator
β Donβt import client-only libraries (e.g., react-toastify, chart.js)
β Donβt write event handlers like onClick inside server components
Best Practices & Patterns β
- ποΈ Parallel Data Fetching: Use
Promise.allto speed up dependent API loads - π‘οΈ User-Facing Errors: Never show broken UIsβalways give user-friendly error states
- π§Ή Separation of Concerns: Server for data, client for UI, clear file organization
- π¦ Automated Checks: Quality tools keep your codebase reliable & readable
Demo π¬
See the app in action! Hereβs a walkthrough of searching users and filtering their repositories:
Running the Demo Locally πββοΈ
git clone https://github.com/Neel2651/github-explorer-rsc.git
cd github-explorer-rsc
npm install
npm run dev
Visit http://localhost:3000, and search any GitHub username to dynamically explore their public repositories!
Enhancements & Practice Tips π
- β Add pagination, infinite scroll, or more advanced search
- π¨ Show followers/following, repo stats, and avatars
- β‘ Optimize further with Next.js server actions, advanced caching, or SWR for stale-while-revalidate data management
- π Deploy on Vercel or Netlify
Published App & Resources π’
- Live App: Demo
- Source Code: github-explorer-rsc Repository
Conclusion π
React Server Components in Next.js 15 offer a powerful framework for building robust, blazing-fast, and highly interactive web applications. By combining server-powered data fetching with rich, client-side UI interactions, youβll stand out as a developer ready for the modern web.
Try the app, extend it for your practice. Happy coding! π©βπ»π¨βπ»
If you enjoyed this guide, please like and share! Follow for more developer tutorials and real-world project walkthroughs.

Top comments (0)