Next.js for Beginners – Static and Server Rendering
June 5, 2020
Next.js makes it easy to build fast and SEO-friendly React apps. It combines the best parts of static sites and server-rendered apps.
You don’t need extra setup to support static generation (SSG) or server-side rendering (SSR). Next.js handles both out of the box.
Basic Concepts
- Pages: Every file in the
pages
folder becomes a route. - SSG: Pre-renders pages at build time using
getStaticProps
. - SSR: Pre-renders pages on each request using
getServerSideProps
.
Example: Static Blog with getStaticProps
// pages/posts.js
export async function getStaticProps() {
const posts = await fetchPostsFromCMS();
return {
props: { posts },
};
}
export default function Posts({ posts }) {
return (
<ul>
{posts.map((p) => (
<li key={p.id}>{p.title}</li>
))}
</ul>
);
}
- This will generate the page at build time.
- Fast load, good SEO.
Server-Side Example
// pages/dashboard.js
export async function getServerSideProps() {
const data = await fetchSecureDashboardData();
return {
props: { data },
};
}
export default function Dashboard({ data }) {
return <pre>{JSON.stringify(data)}</pre>;
}
- This page is generated on every request.
- Use it when data changes often or depends on auth/session.
Routing and Navigation
Next.js uses file-based routing. For links:
import Link from 'next/link';
<Link href="/about">About</Link>
Setup
npx create-next-app my-app
cd my-app
npm run dev
This gives you:
- React 16+
- File-based routing
- Fast builds and hot reload
When to Use What
- Use
getStaticProps
when content doesn’t change often. - Use
getServerSideProps
when content is dynamic. - Use
getStaticPaths
for dynamic routes.
Next.js became a go-to tool for React devs who want performance, simplicity, and a good developer experience—all without losing flexibility.
Recent posts
- At-Least-Once vs. Exactly-Once - Understanding Message Delivery Guarantees
June 12, 2025
Learn about message delivery guarantees in distributed systems. Understand why most production systems implement at-least-once delivery with idempotency rather than attempting exactly-once delivery.
- How Idempotency Saves Your API from Chaos
June 11, 2025
Learn how to implement idempotency in your APIs to prevent duplicate actions and ensure data consistency. Includes practical examples with Supabase and Node.js.
- Vibe Coding ‑ Notes from the First Try
June 6, 2025
Quick lessons from spinning up a new blog with an AI pair‑programmer and Cursor.