zahid ansari
Building scalable systems by applying mental models to code and architecture.
Website
Install this app to stay connected and in the loop.
Building meaningful experiences one pixel at a time 😉.
Made with by Zahid
views
zahid ansari
Building scalable systems by applying mental models to code and architecture.
Website
Install this app to stay connected and in the loop.
Building meaningful experiences one pixel at a time 😉.
Made with by Zahid
views

Share
Confused about 'use client'? Learn the mental model for splitting your app into server and client components for maximum performance.
Next.js 13+ introduced a paradigm shift with React Server Components (RSC). It's powerful, but it introduced a new question for every component: "Should this be a Client or Server Component?"
I initially migrated a dashboard app and made everything
1"use client"1"use client"1// app/dashboard/page.tsx
2// Defaults to Server Component
3import { db } from "@/lib/db";
4import ProjectList from "./project-list";
5
6export default async function DashboardPage() {
7 // Direct database access! No generic API needed.
8 const projects = await db.project.findMany();
9
10 return (
11 <main>
12 <h1>My Projects</h1>
13 {/* Pass data to client component */}
14 <ProjectList initialProjects={projects} />
15 </main>
16 );
17}1"use client";
2
3import { useState } from "react";
4
5export default function ProjectList({ initialProjects }) {
6 const [projects, setProjects] = useState(initialProjects);
7
8 return (
9 <div>
10 {projects.map(p => (
11 <div key={p.id} onClick={() => alert(p.name)}>
12 {p.name}
13 </div>
14 ))}
15 </div>
16 );
17}1children1childrenMastering this split is the key to building fast Next.js apps. Fetch on the server, interact on the client.
Tech Stack: Next.js, React, Server Components