Loading...
This file walks through the correct structure, terminology, and thinking behind creating components in a modern Next.js App Router project using TypeScript (.tsx
).
A component in React (and by extension, Next.js) is a JavaScript/TypeScript function that returns JSX.
There are two main types:
app/
directory)export default function MyComponent() {
return <div>Hello World</div>;
}
use client
useState
, useEffect
"use client";
export default function MyButton() {
const [clicked, setClicked] = useState(false);
return <button onClick={() => setClicked(true)}>Click me</button>;
}
'use client'
When you see:
export default function AboutPage() {
return (...)
}
This is called a:
You may also hear this referred to as:
RFC
,FC
,Page Component
, orApp Route Component
Folder | Purpose |
---|---|
app/ |
Page routes — auto-handled by Next.js |
components/ |
Reusable UI components (buttons, layouts, etc.) |
lib/ |
Utilities, helpers, API fetchers |
styles/ |
Tailwind/global styles |
// src/components/ProfileCard.tsx
interface ProfileCardProps {
name: string;
bio: string;
}
export default function ProfileCard({ name, bio }: ProfileCardProps) {
return (
<div className="border p-4 rounded-md shadow-sm">
<h2 className="text-lg font-semibold">{name}</h2>
<p className="text-sm text-muted-foreground">{bio}</p>
</div>
);
}
Writing a typed functional component with default export in a framework that auto-routes page files.
This is the core building block of every scalable modern web app built with React + Next.js.