NextJS Ebook
NextJS Ebook
The Ultimate
Next.js Ebook
Chapter 1
The Birth
In the first chapter, we explore the evolution of JavaScript and web
The Birth
Not too long ago, in 2015, React.js entered the scene. However, even the
You might wonder why this information is relevant in the context. The
significance lies in the fact that it highlights the timeless truth that
society, our tools and technologies will naturally progress alongside us.
IT industry landscape.
work efficiency and improve performance. In this era, we can still use
doubt.
The Birth
Vanilla JavaScript
document.getElementById('btn')
.addEventListener('click', function () {
alert('Hello, World!');
});
jQuery
$('#btn').click(function () {
alert('Hello, World!');
)
} ;
The Birth
Angular
@Component({
selector: 'app-example',
})
showMessage(): void {
alert("Hello, World!");
React.js
showMessage() {
alert('Hello, World!');
render() {
“Ah? From what I see, there's an increase in the amount of code being
If we look at it solely from this perspective, one would certainly feel that
However, it's important to consider the bigger picture. And that's what
truly matters, doesn't it? In reality, we don't just build "Hello World"
We could have talked about the “big picture” of using React or even
Angular over vanilla code, but that is not the primary focus of this
comparing the previous version of the virtual DOM with the new version.
jQuery. However, even React.js has its own challenges, which have now
Over the course of a year, they continuously added new features such
as file-based routing, automatic code splitting, hybrid rendering,
internationalization, image and font optimization, and many more.
And that’s how we developers now need to shift our focus to the latest
and greatest version, Next.js 13, to build highly capable and production-
ready applications. This exciting evolution opens up new possibilities
and opportunities for creating advanced web applications.
Introduction
In this chapter, we'll dive into Next.js, a flexible React framework. We'll
Introduction
features and capabilities that we will dive into in the upcoming chapter
in detail.
smooth. If you don’t know React.js, you should familiarize yourself with
To help you learn faster, we have a crash course on React.js that covers
all the important things and includes a project for you to practice and
developing applications.
down the user interface into small pieces of code. You describe states
come in:
With Next.js, we won’t have to worry about configuring these tools, thus
investing more time in writing React code.
The constant updates and help from the community make the
development process even easier.
One of the key aspects of Next.js is that it is not just a Frontend React
Framework but a Full Stack React Framework enabling you to write
backend code alongside your frontend code.
How does it contribute to an "Easy Learning Curve"? Wouldn't it be
another thing to learn?
Absolutely not.
The backend aspect of the code you'll be working with is much simpler
than you might anticipate. There's no need to set up anything or
configure any routes as we have to do for any traditional backend app.
Introduction
Improved Performance
With SSG or SSR, the server sends the complete HTML file and minimal
SEO is essential for making your website visible and highly ranked in
search engine (browser) results. When you focus on SEO, you get
several benefits, like more people visiting your website, better user
Giving priority to SEO can greatly impact how well your website does
Always Advancing
On top of that, other technologies like Expo, used for building React
Isn’t that great? Master one feature and effortlessly utilize it across
multiple platforms
However, the list of features provided by Next.js goes beyond what has
been mentioned so far.
"Hmm, alright. I'm willing to trust your insights on the new features of
Next.js and such. However, is it actually being used by people? Are
companies actively seeking professionals with Next.js expertise? Is
there a high demand for it in the industry?"
But hey, that’s just a Google trend. What about the industry? Are people
even creating websites using Next.js?
Sure, let’s take a look at “The Next.js Showcase” which shows different
companies using Next.js:
Notio TE Futuris
Hul Auth Material-U
Netflix Job Product Hun Coco Col
Nik Hyunda Ferrar
HBO Ma Porsch Hashnod
Audibl repl.i Verge
Typeform Marvel
Introduction
Now is the perfect time to seize the opportunity and prepare for the
With this book and the courses we have done and will continue to do,
So, grab a cup of coffee, and let's get started on this exciting journey!
Chapter 3
The Roadmap
The Roadmap is a concise guide to web development essentials. It
covers HTML for structuring web content, CSS for styling and layout, and
JavaScript for interactivity. Learners will grasp important concepts like
semantic tags, visual effects, variables, control flow, functions, and
manipulating the DOM.
This chapter equips beginners with the skills needed to create dynamic
and interactive web applications.
The Roadmap
The Roadmap
Before we start exploring Next.js, reviewing or relearning some basic
concepts is a good idea to make learning easier. It all begins with
building a solid foundation through fundamentals.
These points help you understand the main concepts without focusing
on specific coding details.
Whether or not you have coding experience is not the most important
factor here. What truly matters is understanding the underlying
concepts. The roadmap is designed to introduce you to these concepts
and familiarize you with the beneficial knowledge when aspiring to
become a Next.js Developer.
T he Roadmap
Later in the next chapters, and with our branded courses, you’ll learn
how to do all the code stuff in Next.js. So don’t worry; you have our back!
These points help you understand the main concepts without focusing
Basics
Structure
Elements
Semantics
Forms
Fundamentals
Understand the structure, elements, and attributes of HTML documents
Structure
Box Model
Understand how elements are styled using
Selectors
Learn about different types of selectors to target and style
specific HTML elements. For example,
Typography
Explore text-related properties like
font size weight alignment
Position
Explore how to position an element in different ways such as
relative absolute sticky fixed
Flexbox
Master the flexbox layout to create responsive website layouts
Grid
Dive into CSS grid layout for advanced two-dimensional layouts
The Roadmap
Effects
Transitions
Learn to create smooth transitions using different CSS properties like
Transformations
Explore 2D and 3D transformations like
Animations
Learn how to create animations using keyframes
Advanced (Plus)
JavaScript
Operators
Control Flow
Try & test conditional statements such as if else, switch and loops
Functions
DOM Manipulation
block that we use in different ways with tools like React or Next.js in
in vanilla JavaScript and React.js? The basic idea is the same, but
If you're uncertain about how to learn & create a website using HTML,
CSS, and JavaScript, you can immediately build an attractive Sushi
Website by simply following the right free course:
2 Modern JavaScript
ES6 Features
Arrow Functions
In JavaScript, there are different kinds of functions. One type that
you'll often come across is called the Arrow function. Many prefer
using arrow functions because they are shorter & easier to write.
If you take the time to understand the syntax and how arrow
functions work, it will help you write shorter and more
straightforward functions. This can make your code look cleaner
and easier to read.
Destructuring
A helpful concept that will come in handy when we have to extract
values from arrays and objects
The Roadmap
Destructuring
A helpful concept that will come in handy when we have to extract
values from arrays and objects
Spread Syntax
Allows to expand elements of an array or object into individual
elements
Template Literals
One of the widely used. Using the back sticks ``, we can
interpolate strings with placeholders & expressions
Modules
Learn how to import export code between files to organize the
code
Asynchronous Programming
Promises
Gain an understanding of the concept of promises and why they
are necessary. Learn about resolving and rejecting promises and
utilizing then and catch for handling asynchronous operations.
Async/Await
Explore the usage of async/await to write asynchronous code in a
more synchronous way. This convention is widely adopted as an
alternative to using then and catch for handling promises.
The Roadmap
Fetch API
Discover how to use the Fetch API in the browser to send HTTP
Axios (Plus)
API.
Array Methods
Error Handling
display the errors properly. No user will like to see the complete
red screen with a text — “Error on line 35”. Not even us.
The Roadmap
3 The Ecosystem
Before we proceed learning the libraries and frameworks like
React.js and Next.js, we’ll need some kind of config to setup these
projects:
Foundations
Node.js
A javascript runtime environment that allows us to run JavaScript
code outside of the browser.
It’s needed to work with React or Next.js. Make sure to download it
NPM — Node Package Manager
A tool that manages third party packages. Using it, you can
download different packages needed inside you project like Axios
Bundlers and Compilers
Webpack
Bundlers like webpack or Parcel help combine our JavaScript files
and other assets into a single bundle
The Roadmap
Babel
Transpilers like Babel convert modern JavaScript code to a version
that works in all browsers
4 React JS
From here, you’re efficiently learning Next.js. The same concepts
are as it is used in the Next.
Fundamentals
Components
Think in terms of components. Learn to break the code or the UI in
small manageable components for reusability & maintainability
There are two ways in which we can create a component i.e.,
Class Componen
Function Component — Widely used
The Roadmap
State
Learn how to create and manage state — A small store that holds
a particular data of the application
Props
Learn how to pass props (a piece of data) between components
Events
Learn how to handle user interactions, such as clicks and form
submissions, using event handlers.
Conditional Rendering
Learn how to conditionally render components and render
dynamic list of data using the mapping techniques
P.S., Don’t forget to learn about the special “Key” prop when rendering
the dynamic list with map method.
The Roadmap
Hooks
Router
State Management
Style
including
styled-components Emotion
Forms
HTTP Requests
Learn how to make requests using libraries like Axios or the built-in
Fetch API
Requests in React, you can check out our FREE and highly popular Crash
Course on YouTube:
The Roadmap
If you want to enhance your skills in state management using tools like
Redux Toolkit, you can explore our professional-level course:
5 Backend
developer.
Basics
HTTP Protocol
concepts
APIs
REST
HTTP Methods
Status Code
200 — ok
201 — created
HTTP Headers
Request and Response
Resource URI
CRUD
Understand the concept of CRUD operations
User Sessions
JWT — JSON Web Token
Cookies
Permissions and Roles
Database
Relational Database
MySQL
PostgreSQL
NoSQL Database
MongoDB
Redis
Deployment
Environments
Production
Development
Staging
The Roadmap
Hosting Platforms
Vercel Netlify Firebase Render
Advanced (plus)
CI/CD — Continuous Integration/Continuous Deployment
Docker
If you want to enhance your skills in state management using tools like
Redux Toolkit, you can explore our professional-level course:
And now, at last, we will dive into the Next.js roadmap. It may not be
necessary, as the content of this book is organized in a manner where
each chapter serves as a guiding milestone, and it’s the only resource
you need (alongside some Build and Deploy courses, of course) to
master Next.js!
6 The Next.js
Fundamentals
Architecture
Understand the architecture of a Next.js application including
different files and directories i.e., app directory vs pages directory.
Client Server
Style
Next.js has built-in support for CSS processors like Sass to CSS
modules. Try different types of styling with Next.js to find the one
Data Fetching
methods include:
Learn how to use SEO strategies and leverage the use of Metadata
API of Next.js
Points to learn:
Authentication
Implementing custom email/password or social authentication
becomes hassle-free with NextAuth in Next.js. Few auth libraries
you can use with Next.js to speed up the development process:
NextAuth Clerk
API routes
Explore how to create API routes — the backend:
Route Handlers
Create custom request handlers
Static Route Handlers Dynamic Route Handlers
Middleware
Supported HTTP Methods
NextResponse
Database
Discover how to incorporate various types of databases into your
Next.js application by utilizing API routes.
MongoDB Postgres Prisma
If you're someone who prefers video content over reading, you'll find our
best and most up-to-date Crash Course on Next.js 13 on YouTube very
enjoyable. This course not only covers the fundamentals of Next.js but
also guides you in building a Full Stack project with authentication,
utilizing the latest features of Next.js 13:
Keep in mind that real progress happens when you actively do coding.
So, grab coffee, find a quiet spot, and start coding to make things
happen.
Chapter 4
How it works
We also introduce the React way, where the server sends a minimal
HTML file and a bundled JavaScript file, and React manipulates the
virtual DOM for efficient rendering. Finally, we discuss the Next.js way.
How it works
How it works
You might be itching to start with Next.js code, right?
If your why isn’t clear, you’ll have no idea what you’re doing, and you’ll
blame it on Next.js by saying that it’s an overrated piece of technology.
That will only showcase your lack of knowledge. It's a foolproof recipe to
amaze everyone with your impressive ignorance.
So, perfect your why and your how will come naturally.
Let’s time-travel a bit to see how things were used to work with
different technologies.
When a user visits such a website, their browser (the client) sends a
request to the server (another computer where the site is hosted)
asking for the content to be displayed.
The client's browser receives these files and begins by analyzing the
HTML file. Then, it applies the styles from the CSS file and implements
any user interaction, such as event handlers or dynamic behavior,
specified in the JavaScript file on the webpage.
If your why isn’t clear, you’ll have no idea what you’re doing, and you’ll
blame it on Next.js by saying that it’s an overrated piece of technology.
That will only showcase your lack of knowledge. It's a foolproof recipe to
amaze everyone with your impressive ignorance.
So, perfect your why and your how will come naturally.
Let’s time-travel a bit to see how things were used to work with
different technologies.
When a user visits such a website, their browser (the client) sends a
request to the server (another computer where the site is hosted)
asking for the content to be displayed.
How it works
Request
three files i.e., the HTML, CSS, and JavaScript (only if any JavaScript code
analyzing the HTML file. Then, it applies the styles from the CSS file and
The client will send additional requests to the server if the website has
multiple pages. In response, the server will send the three files
Most processing occurs on the client side, meaning the user's web
browser is responsible for rendering the HTML page and executing any
JavaScript code present.
However, if the website is complex and the user's device needs more
capabilities, it can strain the browser and create a burden for it to
handle.
Bandwidth
As the server sends complete files to the client for each page request, it
increases bandwidth usage. This becomes particularly significant when
dealing with complex websites containing numerous pages and video
and audio clips scattered throughout the site.
Load Time
The initial page load time may be longer when compared to the latest
technologies. This is due to the complete transfer of files for each
request. Only after the server has sent all the necessary files and the
browser has finished parsing everything will we be able to view the
website's content.
How it works
When you access a React website, the client's browser sends a request
to the server for the webpage content. In response, the server sends a
minimal HTML file, which serves as the entry point for the entire
application, along with a bundled JavaScript file.
Processing
SEO
The issue is that search engine crawlers might need help fully
accessing the website's content since everything is handled through
JavaScript and only rendered on the client side. As a result, it impacts
the website’s visibility in search engine results
How it works
Typically, when a user visits a Next.js site, the client sends the request to
the server, which starts executing the React Components, generates
HTML, CSS, and JavaScript files, and sends back the fully rendered HTML
to the client as a response. This file includes initial content, fetched
data, and React component markup, making the client render it
immediately without waiting for JavaScript to download and execute.
But it doesn’t mean we don’t receive any JavaScript files. The server will
still send the JavaScript code as needed for the user interaction. From
here, Next.js takes over and performs client-side hydration
Have you ever encountered the issue of a hydration error where the
user interface doesn't match what was originally rendered on the
server?
For subsequent requests, you have full control over where to render
your page content i.e., either on the server side (SSR) or the client side
(CSR).
In the following chapters, we’ll talk in-depth about different types of
server-side rendering along with client-side rendering and when and
where to render what.
Chapter 5
Create a Next.js
Application
In this chapter, we lay the foundation by understanding how the web
works before diving into Next.js code. We explore the traditional
approach of HTML, CSS, and JavaScript websites, where the server
sends complete files to the client for each page request.
We also introduce the React way, where the server sends a minimal
HTML file and a bundled JavaScript file, and React manipulates the
virtual DOM for efficient rendering. Finally, we discuss the Next.js way.
Create a Next.js Application
If you haven't installed Node.js before, you can visit this link and start
downloading it. The website will give you two options based on your
operating system: LTS and Current. The LTS (Long Term Support) version
is the most stable, while the Current version is like a "Work in Progress"
that adds new features but may have some bugs.
node - v
Create a Next.js Application
node -v
18.16.1
After downloading Node.js and VSCode, let's set up your first Next.js
application.
Go to the desired location where you want to create your project. It can
be any location, but it's advisable to maintain an organized structure.
Create a new folder inside that location and name it "NextEbook." If you
prefer a different name, feel free to choose one. This folder will hold all
the code we will cover in this ebook.
Now, let's proceed with the following steps to open the folder we just
created in our chosen code editor, which is VSCode:
Launch VSCode
Click on the "File" option in the top menu bar
From the dropdown menu, choose "Open Folder.
Browse to the location where you created the "NextEbook" folder
Select the "NextEbook" folder
Click on the "Open" button.
Create a Next.js Application
Following these steps, you can view your "NextEbook" folder in VSCode.
VSCode provides its own built-in terminal, eliminating the need for
developers to open the OS Terminal or Command Prompt separately.
With the inline terminal in VSCode, we can perform all necessary tasks
within the application.
To open the terminal, press ctrl + `(backtick) or click on the
"Terminal" option in the top menu bar. From the dropdown menu, select
"New Terminal." The terminal window will appear as follows:
For the final, let’s now create our Next.js application. There are two
options:
Automatic Installatio
Manual Installation
Create a Next.js Application
On the other hand, NPX, short for Node Package Runner, is a command-
line tool. It lets us execute packages without installing them globally on
our system. It's important to note that npx is used to run command-line
tools and execute commands from packages, but it doesn't handle the
installation of packages. That responsibility falls to npm, which takes
care of package installation.
Let's move on from the theoretical discussion and proceed with the
command that will automatically install the necessary packages for
running a Next.js application.
npx create-next-app@latest
As soon as you press enter, it will prompt you to confirm whether it can
download the required packages. Please select "yes" to proceed with
the installation.
During the installation process, we will encounter a series of prompts
individually. These prompts allow you to choose the specific features
and configurations we desire for our Next.js application.
Let's choose not to include TypeScript, ESLint, and Tailwind CSS. In the
upcoming chapters, we will explore these options in detail.
Create a Next.js Application
If you see the installation process carefully, you’ll see “Using npm.”
npx is used solely to execute commands from packages, while npm
handles the installation of those packages.
And there you have it! The Next.js application has been successfully
installed
Now, let's explore what's inside. Click on the "introduction" folder or the
name you chose for your project. Inside, you will find several files and
folders.
App
It’s the root of the application, where we'll create various client
(frontend) routes and potentially write backend code. Initially, you'll find
some starter files in this location, including:
Create a Next.js Application
favicon.ico
globals.css
This file holds the CSS code for the application. It is a global file where
you can define CSS variables, import fonts, or perform other CSS
initialization tasks.
You can keep the file, rename it, or even move it to a different location. It
doesn't matter. However, if you make any changes to this file, you must
update any other parts of the application that rely on it.
Create a Next.js Application
global.css
:root {
--max-width: 1100px;
--border-radius: 12px;
--foreground-rgb: 0, 0, 0;
--primary-glow: conic-gradient(
#16abff33 0deg,
#0885ff33 55deg,
#54d6ff33 120deg,
#0071ff33 160deg,
transparent 360deg
);
--secondary-glow: radial-gradient(
);............
layout.js
It’s the main entry point of the application. The root. The parent. The
layout. Whatever you prefer to call it.
If you write anything in there, it’ll appear on each & every client
(frontend) route. It’s universal.
If you need to import fonts, add metadata, wrap the application with
Redux, or show a Navbar, this is the place to do it. All these tasks can be
performed within this file.
Create a Next.js Application
page.js
It’s an alias of the home route i.e., “/”. It's important not to confuse this
file with layout.js. Whatever you write inside page.js will be displayed
only on the "/" route, while anything inside layout.js will appear across all
routes, including the home route i.e., “/”.
page.module.css
If you closely examine the code, you will notice the presence of the
following:
Node Modules
No need to worry, though. You don't have to interact with or visit this
directory in the future (unless something terrible happens). npm
automatically manages the node_modules folder when we install or
uninstall node packages.
Public
.gitignore
The .gitignore is a special text file that tells Git, the version control
system, to exclude certain files and directories from being tracked.
universe!
jsconfig.json
Remember the prompt that appeared when we ran the Next.js CLI tool?
chose "No".
Create a Next.js Application
By default, when we want to import code from one file into another, we
use relative paths like this:
This is the correct, but sometimes long and complex, relative path.
"compilerOptions": {
"paths": {
"@/*": ["./*"]
}
Cr ea t e a N e xt .js A ppl i ca ti on
i.e., using @/* for any files and folders located in this location ./* i.e., the
root!
Feel free to customize the alias to your preference. You can change @/*
package-lock.json
Well, let me tell you, it's actually quite important. This file, called
dependencies.
completing your work, you share the project code with your manager,
but you omit the package-lock.json file, thinking it's not essential.
package.json
Think of this as an info card that tells about you — who you are, where
you are from, etc. but with more complete details.
dependencies
List of the packages that are necessary for the project to run the
production environment
devDependencies
List of packages that are only needed during the development process.
For example, linting packages like eslint.
This way, the package.json file records all the packages required for
the project, making it easier to manage and reproduce the
development and production environments accurately.
Other than that, we can see another part i.e., “scripts”. It contains
executable commands or scripts using npm. We can completely
customize it. Through these commands/scripts, we run tests, build a
project, start a development server, or deploy the application.
README.md
It’s a like a manual or guidebook for your project — a text file where we
can write down important information about our project, such as how to
install it, what it does, and how others can contribute to it.
Having a good README helps people understand what our project is all
about and how they can use it or get involved. It's like giving them
directions or instructions on how to make the most of our project.
Now, let's finally run our application. We need to execute one of the
commands from the "scripts" section we just mentioned, specifically the
"dev" command.
cd introduction
Create a Next.js Application
The "cd" command, which stands for "change directory," will navigate us
Now run,
3000. To see the application in action, open your preferred web browser
and type the URL: http://localhost:3000. If you have followed all the
running as expected:
http://localhost:3000
Phew, a lot of explaining just to cover the initial file and folder structure.
But it’s of no use if we don’t take any actions. Let’s change few things
Open the page.js file and delete all the existing code. We'll start fresh
by creating the Home component.
export default function Home() {
return (
<main>
</man>
)}
After making the changes, save the file and return to your browser. If
you visit the localhost again, you should see the updated content of
"Hello World " without manually refreshing the page. This is possible
because of the Fast Refresh feature of Next.js, which automatically
reflects the changes in real time as we edit the code.
Now, open the layout.js file and add text inside the body tag:
import './globals.css';
};
return (
<html lang="en">
<body className={inter.className}>
{children}
</body>
</html>
);
}
Create a Next.js Application
{children}
</body>
Create a Next.js Application
<body className={inter.className}>
{children}
</body>
the application, starting from the home route and extending to any
return (
<html lang="en">
<body className={inter.className}>
{children}
</body>
</html>
Clear enough?
Amazing! Before you rush to start the next chapter, I have a few tasks for
you to complete:
Create a Next.js Application
Tasks
Comment down the {children} inside the RootLayout and see if you
can still see the “Hello World ”
import './globals.css'
return (
<html lang="en">
<body className={inter.className}>
</body>
</html>
We also introduce the React way, where the server sends a minimal
HTML file and a bundled JavaScript file, and React manipulates the
virtual DOM for efficient rendering. Finally, we discuss the Next.js way.
Client Vs. Server
side rendering to get the best of both worlds. But we need to find out
which parts of the application are rendered on the server side. Can we
mean?
Client
The client refers to the device you are currently using, such as your
Server
all the code for our application is stored. When the client, our device,
pages. This meant that only the route pages like "/", "/about", "/projects",
And that, my friends, is where the app directory comes into action. It not
only introduced many features but also brought about a revolutionary
change, i.e., — Component level Server Side Rendering.
And as discussed above, we’ll overcome our limitations with the pages
directory. Rather than fetching and passing data to components
separately, we can fetch the data directly within the component,
turning it into a server component.
Smaller JavaScript bundle size: The size of the JavaScript code that
needs to be downloaded by the browser is reduced.
Client Vs. Server
Faster initial page load for better accessibility and user experience:
Users can see the content more quickly, leading to a smoother
browsing experience.
Ask yourself:
Client Vs. Server
Component Component
Fetch data.
cd ..
Now go to the app folder, then to the page.js file, and delete all other
app/page.js
console.log("Where do I render?")
return (
<main className={styles.main}>
<h2>Welcome </h2>
</main>
If you prefer, you can delete everything else from the page.module.css
file and keep the styles only for the main tag of HTML.
app/page.module.css
.main {
display: flex;
flex-direction: column;
align-items: center;
padding: 6rem;
min-height: 100vh;
After adding a console log in our page.js file, let's open our web browser
to see if it appears there:
Client Vs. Server
http://localhost:3000
The terminal! Let's return to our terminal and check if the mentioned log
"use client";
return (
<div>
</div>
);
};
components/ExampleServer.jsx
return (
<div>
</div>
);
};
Now, first import & use the ExampleClient component inside the app/
page.js file:
app/page.js
console.log("Where do I render?")
return (
<main className={styles.main}>
<h2>Welcome </h2>
<ExampleClient />
</main>
}
Client Vs. Server
Let’s play around with these components a little more. Now, import the
ExampleServer component inside the app/page.js file
Client Vs. Server
app/page.js
console.log("Where do I render?")
return (
<main className={styles.main}>
<h2>Welcome </h2>
<ExampleClient />
<ExampleServer />
</main>
And now, if we visit the browser, along with showing both client-server
component text on the website, it’ll only show the “I'm Client Component
:)” log inside the browser’s console:
http://localhost:3000
Client Vs. Server
Whereas the terminal will show all the three console logs
All good!
For the final play, let’s remove the ExampleServer from app/page.js
and add it inside the components/ExampleClient.js
app/page.js
console.log("Where do I render?")
return (
<main className={styles.main}>
<h2>Welcome </h2>
<ExampleClient />
</main>
}
Client Vs. Server
components/ExampleClient.jsx
"use client";
return (
<>
<div>
</div>
<ExampleServer />
</>
);
};
Hit save and see the result in both the Terminal and Browser console.
http://localhost:3000
file, all the other modules imported into that file, including child server
Consider "use client" as a dividing line between the server and client
code. Once you set this boundary, everything inside it becomes client
code.
Before we dive into yet another feature of Next.js, take some time out to
work on the below tasks to solidify your learning so far:
Tasks
Add “use client” inside the app/page.js file and see where the
console logs are appearing:
app/page.js
"use client"
console.log("Where do I render?")
return (
<main className={styles.main}>
<h2>Welcome </h2>
<ExampleClient />
</main>
}
Client Vs. Server
What are the latest features of the app directory regarding the
client/server rendering?
The End
We're just scratching the surface. Stay tuned for the next update as we
release more chapters that unlock the full potential of Next.js 13.
Give yourself a pat on the back for completing all the chapters thus far.
We would greatly appreciate hearing your suggestions or feedback.
Feel free to provide your honest input through this link.
With your feedback and collaboration, we will bring you the best version
of Next.js in the coming weeks. Thank you!