What carries over
| React concept | How it works in Next.js | Why it still matters |
|---|---|---|
| JSX | JSX files (.tsx or .jsx) are compiled by the same Babel pipeline. |
All component rendering logic stays identical. |
| Function components & hooks |
useState, useEffect, useContext, custom hooks, etc., are imported from react exactly the same way. |
State management and side‑effects remain component‑local. |
| Component composition | You still compose UI by nesting components, passing props, and using children. | The mental model of “building UI from small pieces” does not change. |
| React Router vs. Next.js routing | The <Link> component exists in both ecosystems, but Next.js uses file‑system routing. |
Navigation still uses <Link href="/about">. |
| CSS‑in‑JS / CSS Modules |
styled-components, emotion, or CSS Modules (.module.css) work unchanged. |
Styling strategies you already know continue to apply. |
| Testing with Jest / React Testing Library | Test files live alongside components; the same APIs (render, screen, fireEvent) are used. |
Unit and integration tests remain the same, only the import paths may differ. |
| TypeScript support |
tsconfig.json is still the source of truth; you can use tsx files everywhere. |
Type safety carries over without extra configuration. |
| Environment variables |
process.env.NEXT_PUBLIC_* works like any process.env you already use. |
No need to learn a new way to read env vars; just the naming convention. |
| SSR concepts (hydration) | You already know that the server renders HTML and the client “hydrates” it. Next.js just automates the server side. | Your mental model of hydration is already correct. |
What's new
Next.js adds a layer of conventions and built‑in features that React alone does not provide. Below is a side‑by‑side comparison of a common task: fetching data for a page.
Pure React (client‑side fetch)
// src/pages/UserList.jsx
import { useEffect, useState } from "react";
export default function UserList() {
const [users, setUsers] = useState([]);
useEffect(() => {
fetch("/api/users")
.then((res) => res.json())
.then(setUsers);
}, []);
return (
<ul>
{users.map((u) => (
<li key={u.id}>{u.name}</li>
))}
</ul>
);
}
Next.js (static generation with getStaticProps)
// pages/users.tsx
import { GetStaticProps, NextPage } from "next";
type User = { id: number; name: string };
type Props = { users: User[] };
export const getStaticProps: GetStaticProps<Props> = async () => {
const res = await fetch("https://example.com/api/users");
const users = await res.json();
return { props: { users } };
};
const UsersPage: NextPage<Props> = ({ users }) => (
<ul>
{users.map((u) => (
<li key={u.id}>{u.name}</li>
))}
</ul>
);
export default UsersPage;
What changed and why
-
File‑system routing – In Next.js the file
pages/users.tsxautomatically becomes the/usersroute. No explicit router configuration is needed. -
Data‑fetching primitives –
getStaticPropsruns at build time (or on-demand with ISR). The component receives data as props, eliminating the need for a client‑sideuseEffectfor the initial load. -
Type safety –
GetStaticPropsandNextPageare exported fromnext, giving you typedpropsout of the box. - Performance – The HTML is generated ahead of time, so the first paint is fully rendered without a loading spinner.
Other notable new concepts:
-
pages/api– Serverless functions live next to your UI code. -
Image optimization –
<Image>fromnext/imageautomatically serves responsive, WebP‑enabled images. -
Middleware – Edge‑runtime code in
middleware.tscan run before a request reaches a page. -
App Router (optional) – The newer
app/directory introduces React Server Components, but the classicpages/router remains fully supported.
Common pitfalls
| Pitfall | Symptom | Fix |
|---|---|---|
Using window or document at the top level |
“ReferenceError: window is not defined” during build or SSR | Guard the code (if (typeof window !== "undefined")) or move it inside useEffect. |
Forgetting the public/ prefix for static assets |
Images load locally in dev but 404 in production | Place assets in public/ and reference them as /my‑image.png. |
Mixing getStaticProps with useEffect for the same data |
Duplicate network requests, stale UI | Choose one source of truth: either fetch at build time (getStaticProps) or client side (useEffect). |
Incorrect Link usage |
Full page reload instead of client navigation | Use <Link href="/about"><a>About</a></Link> (or the newer <Link href="/about">About</Link> in Next 13+). |
Over‑using getServerSideProps |
Slow page loads because every request hits the server | Prefer getStaticProps with Incremental Static Regeneration (revalidate) when possible. |
Neglecting the NEXT_PUBLIC_ prefix |
Env var is undefined on the client | Prefix any variable you need in the browser with NEXT_PUBLIC_. |
Improper file naming in pages/ |
Route does not match expected URL (e.g., Home.jsx vs index.jsx) |
The default route is pages/index.{js,tsx,jsx}; other routes map directly to file names. |
Using next/link with external URLs |
Link triggers client navigation to an external site, breaking the SPA model | Use a regular <a href="https://example.com"> for external links or add target="_blank". |
Your 30‑day plan
Week 1 – Foundations
- Create a fresh Next.js project
npx create-next-app@latest my-next-app
cd my-next-app
npm run dev
-
Explore the file‑system router – Add
pages/about.jsx,pages/blog/[slug].jsx, and observe URL mapping. - Convert an existing React component (e.g., a button library) into a Next.js component; keep the same props and styling.
-
Mini project: Build a static “Portfolio” site with Home, About, and Contact pages, using only
pages/routing and CSS Modules.
Week 2 – Data fetching & API routes
-
Learn
getStaticPropsandgetStaticPaths– Fetch a list of posts from a public API and generate a detail page for each. -
Introduce
getServerSideProps– Create a dashboard that shows user‑specific data based on a cookie. -
Create an API route in
pages/api/hello.tsthat returns JSON; call it from the client side withfetch. - Mini project: Build a “News Reader” that statically generates article list pages and uses an API route for a comment submission form.
Week 3 – Performance & advanced features
-
Use
<Image>– Replace<img>tags withnext/imageand experiment withlayout="responsive"andplaceholder="blur". -
Implement Incremental Static Regeneration – Add
revalidate: 60to agetStaticPropspage and observe updates without a rebuild. -
Add middleware – Write a simple
middleware.tsthat redirects unauthenticated users to/login. - Mini project: Create a “Product Catalog” with static product pages, ISR for price updates, and a protected admin route guarded by middleware.
Week 4 – Full‑stack polish & testing
-
Integrate TypeScript (if not already) – Rename files to
.tsx, addtsconfig.json, and fix any type errors. -
Write unit and integration tests using Jest and React Testing Library; test a page that uses
getStaticProps. - Deploy to Vercel (or another platform) – Connect the repo, run a production build, and verify that ISR works in the live environment.
- Mini project: Refactor the “Product Catalog” into a production‑ready app with CI, tests, and a live deployment.
FAQ
How do I decide between getStaticProps and getServerSideProps?
Use getStaticProps for data that changes infrequently or can be regenerated on a schedule; choose getServerSideProps when you need fresh data on every request (e.g., auth‑dependent pages).
Can I still use React Router inside a Next.js app?
You can, but it’s unnecessary for page navigation because Next.js handles routing via the pages/ (or app/) directory. Use React Router only for deeply nested UI state that isn’t reflected in the URL.
Do I need to install React separately?
No. Next.js bundles the appropriate version of React, so you import from "react" as usual.
How does CSS Modules naming differ from plain CSS?
A file named Button.module.css is imported as an object (import styles from "./Button.module.css"), and class names are scoped automatically (className={styles.primary}). This prevents global leakage without extra configuration.
Keep going
- See what already transfers: take the free React → Next.js readiness check
- The full React → Next.js roadmap, topic by topic
- Related: Migrating Secrets Management: AWS Parameter Store vs Azure Key Vault
Originally published at switchbyskill.com.
Top comments (0)