Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Why Next.js  ›  Lesson

Why Next.js

Why Next.js 10 minReact draws components but leaves routing, data loading, server rendering and bundling to you, and Next.js is a framework that supplies all of them with sensible defaults.

Why Next.js

You have learned React and want to build Trailhead, a guide to local hiking trails: a home page, a list of trails, a page for each trail and a small API for a phone app. React will happily draw every one of those screens. But the moment you ask "how does /trails/misty-ridge find the right component?" or "how does Google read this page?", React has no answer. That gap is why Next.js exists.

The rule

React draws the parts; Next.js builds the house around them.

React is a library. It does one job very well: turning data into components and keeping the screen up to date. Everything around that job is left to you:

  • Routing: which component shows for which URL.
  • Data loading: where and when the trail list is fetched.
  • Rendering on the server: sending real HTML instead of an empty page.
  • Building: bundling, splitting and minifying the code for production.
  • Backend endpoints: somewhere to answer GET /api/trails.

Next.js is a framework built on React. It makes those decisions for you and turns them into conventions. The best-known one: a folder is a URL.

app/page.tsx                # the page at /
app/trails/page.tsx         # the page at /trails
app/trails/[slug]/page.tsx  # every page like /trails/misty-ridge

You still write ordinary React components. Next.js decides when they run, where they run, and how the result reaches the browser.

A library is something your code calls. A framework is something that calls your code: you put a file in the right place with the right name, and Next.js picks it up.

The shortcut

When you meet a new feature, ask "Is this drawing, or is this plumbing?" Drawing a card, a button or a list is React. Plumbing (URLs, data, HTML delivery, builds, APIs) is what Next.js supplies.

Sorting Trailhead's needsStep 1 of 4
  1. A trail card with a photo and distance

    Drawing. A React component, TrailCard, with props.

The trap is thinking Next.js replaces React. It does not. Every page you write in Next.js is a React component; the framework just gives it a home.

Drills

Answer fast — trust the rule.

quick drill

Which job does React itself handle, without a framework?

quick drill

What is the key difference between a library and a framework?

quick drill

In Next.js, what creates the page at /trails?

quick drill

Trailhead wants a star-rating widget. Which part of the stack is that mainly about?

Remember

  • React draws the parts; Next.js builds the house: routing, data, server HTML, builds and APIs.
  • Shortcut: ask "drawing or plumbing?" to know whose job it is.
  • Trap: Next.js does not replace React; every page is still a React component.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainLibrary or framework?

A friend says: "React is enough, why would I add Next.js?" Using the Trailhead trail guide as the example, explain what React alone gives you, what you would have to build or choose yourself, and what Next.js provides instead.