🎓 A1Learner
🔍
0 of 50 lessons completed

Next.js Your First Page

The starter page is a demo. Replace it with the Bookshelf home page, the first real page of this course.

The Bookshelf home page

The file lists three books and maps each one to a list item. The read flag picks Read or To read.

type Book = {
  title: string;
  author: string;
  read: boolean;
};

const books: Book[] = [
  { title: "Dune", author: "Frank Herbert", read: true },
  { title: "The Hobbit", author: "J. R. R. Tolkien", read: false },
  { title: "Pride and Prejudice", author: "Jane Austen", read: true },
];

export default function Home() {
  return (
    <main>
      <h1>My Bookshelf</h1>
      <p>Three books. Two read. One still waiting.</p>
      <ul>
        {books.map((book) => (
          <li key={book.title}>
            {book.title} by {book.author} — {book.read ? "Read" : "To read"}
          </li>
        ))}
      </ul>
    </main>
  );
}

The built page holds the books

The check reads the built page file. The heading and all three titles are in it.

grep -o "My Bookshelf" .next/server/app/index.html

Example

npm run build

Key points

  • The home page lives in app/page.tsx. Open that file to change the home page.
  • A page is a React component with a default export.
  • The list holds three books. Each book has a title, an author, and a read flag.
  • map turns the list into list items. One item per book.
  • key tells React which item is which. The book title is the key.
  • The read flag picks the words after each book: Read or To read.

In this example, one command builds the app for real. The route table lists the pages the build found. The home page is the / route, and the not-found page is the /_not-found route. The circle mark means each page was built ahead of time as static content. Two routes, one build, and the Bookshelf home page is live in the built app.

Note

Keep the starter files around until the build below passes. A green build means the new page works.

Try it Yourself

Edit the code, then press Run.

Running is simulated · TypeScript Playground

Exercise

Which file do you edit to change the home page?