You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Server-Side Rendering (SSR) and Static Site Generation (SSG)
Explanation of SSR and SSG
Define Server-Side Rendering (SSR) and Static Site Generation (SSG)
Explain the benefits of SSR and SSG over client-side rendering
Use cases for SSR and SSG
Discuss when to use SSR (dynamic data, personalization, etc.)
Discuss when to use SSG (static content, blogs, documentation, etc.)
Server Components for SSR
Explain how Server Components can speed up load times by directly sending HTML to the browser
Introduce the "use server" directive, allowing React components to be rendered on the server
When to Use Client vs. Server Components?
Re-iterate how Next.js distinguishes client and server components ("use server" and "use client")
Illustrate how these fit into the SSR and SSG concepts
Introduction to Next.js App Router
Overview of Next.js routing system
File-based routing system in Next.js
Dynamic Routes
Mention the Next.js Link Component & why it is used
Advantages over traditional client-side routing
Improved performance with built-in server-side rendering and static site generation
Simplified routing configuration
Nested layouts and nested routes
Basic Next.js Routing
Explanation of routes
Creating subfolders in app directory with page.jsx file.
Create a component that defines a page
Next.js Router Hooks
Understanding the useParams Hook (client-only)
Explain the purpose of the useParams hook
Discuss how to use the [] bracket notation to mark params in a folder/filename
Demonstrate how to use useParams to access the params of the current path
Understanding the useSearchParam Hook (client-only)
Explain the purpose of the useSearchParams hook
Demonstrate how to use useSearchParams to access the query strings
Working With the useRouter Hook (client-only)
Introduce the <Link> component for most links
Discuss the need for redirects in web applications (authentication, URL changes, etc.)
Introduce the useRouter hook
Explain how to access various router properties (push, replace, etc.)
Demonstrate programmatic navigation using router.push and router.replace
Working With params and searchParams in Server Components
Mention that the aforementioned hooks don't work in Server Components (Next.js pages)
Explain that we can use the object Next.js passes to page functions to get params and searchParams on the server-side
Demonstrate usage with a sample page function like this:
// Url /{id}?query={query}exportdefaultasyncfunctionIdPage({ params, searchParams }){constid=(awaitparams).id;constquery=(awaitsearchParams).query;return<h1>Hello,theid is {id}andquery is {query}</h1>}
Advanced: Server Functions & API Routes
Server Functions
Explain Server Functions (previously "Server Actions") as a mechanism to run JavaScript code on the server that hosts the website
Discuss how this is different from running JavaScript in the user's browser
Fetch the placeholder blog posts in a Server Component, using fetch, from JSON Placeholder API
Show a list of all unique userIds in the JSON
Show a count of the unique users
4. Client vs. Server Exercise
Create a component that renders 10 articles from a JSON array
Download the current JSON from the Vercel blog API – Attention: Rate limits apply. It's best if one person fetches the JSON and posts it in the team's Slack channel
Create a page that renders the 10 articles on the server
Create a page that renders the 10 articles on the client
Use your browser's performance panel to measure the performance of both versions
Create a Blog Website With Dynamic Routes to Different Blog Posts
Create a route /blogs that displays blogs
Create a dynamic route for a blog post that displays the title from the route. For example, /blogs/my-new-post should dynamically display "My New Post".