WhoBuilt

Introduction to Next.js and React

Dec 4, 2023· 1 h 22 min· 85K views·Watch on YouTube

Speaker

Lee Roberson, a developer at Vercel, introduces React and Next.js by building and deploying a quiz app; no co-hosts are identified.

Set up a minimal Next.js app

Lee starts with the tools and dependencies, then creates a minimal app with a root layout and page that displays “Hello, world.” He explains the App Router, the older Pages Router, and Fast Refresh, showing how edits appear in the browser as he saves.

Learn React through components

Lee introduces JSX, component composition, props, and children by turning a simple page into reusable components. He also demonstrates importing a component from a separate file and using an external package to render a tweet.

Build quiz pages and fetch data

The example app becomes a quiz site with a list page and dynamic quiz routes. Lee shows internal navigation with Next.js Link, then connects a Postgres database to fetch quiz titles, questions, descriptions, and answers. He also explains loading UI with Suspense and compares Tailwind, inline styles, and CSS Modules.

Reveal answers and create quizzes

Lee uses a form action and server action to add a query parameter to the quiz URL, letting the page show which answer is correct without client-side state. A second form inserts new quizzes and answers into Postgres, while revalidatePath refreshes the quiz list after submission.

Deploy and continue learning

Lee configures a database environment variable and deploys the app with the Vercel CLI. The finished site has a shareable URL and can read the quiz data from the database. He recommends the React documentation and a longer Next.js dashboard course for further study.

Takeaways

  • Build a small app while learning React concepts so JSX, props, and component composition have concrete examples.
  • Use file-system routes and dynamic segments to model pages such as individual quizzes.
  • Fetch data close to the component that renders it, and use Suspense to define loading behavior.
  • Use server actions and URL parameters when an action should produce a shareable page state.
  • After a database mutation, revalidate the relevant route so the UI reflects the updated data.

Mentioned in this talk

Search inside this talk

What was claimed 8

  • uses
    The talk says the framework API is built on infrastructure developed at Vercel
    “Vercel is an amazing platform, and it's arguably the best place to deploy your Next.js projects”
    6:42inWhy I’m Using Next.js in 2020YouTube
    Verified3 sources· Talk
  • feature
    Next.js: The App Router uses special layout and page files to define routes
    “There are two different routing systems in Next.js.”
    YouTube
    Unverified1 source· Talk
  • feature
    React: Components let developers compose reusable user interface pieces
    “You get to write components, and React takes care of the rest.”
    YouTube
    Unverified1 source· Talk
  • feature
    Link: Enables fast internal navigation and can prefetch destinations
    “It was really fast. I didn’t have to do the full browser transition.”
    YouTube
    Unverified1 source· Talk
  • uses
    “I'm going to use Postgres as our database.”
    YouTube
    Unverified1 source· Talk
  • feature
    React Server Components: Components can be asynchronous and fetch data directly
    “you can mark components as asynchronous and fetch data directly”
    YouTube
    Unverified1 source· Talk
  • feature
    Suspense: Lets developers provide fallbacks while asynchronous content loads
    “provide a fallback. It could be a loading skeleton or a spinner”
    YouTube
    Unverified1 source· Talk
  • feature
    Vercel: Deploys the application and provides a shareable URL
    “get our site online, with a URL we can share with the world”
    YouTube
    Unverified1 source· Talk

Related talks