Next.js is a React-based framework designed for creating
full-stack web applications.
Next.js is a React-based framework designed for creating
full-stack web applications.
React.js
It's challenging to develop a fully-functional application that is ready for production.
Next.js is a React-based framework designed for creating
full-stack web applications.
React.js
It's challenging to develop a fully-functional application that is ready for production.
React is a library designed specifically for creating
user interfaces.
Next.js is a React-based framework designed for creating
full-stack web applications.
React.js
It's challenging to develop a fully-functional application that is ready for production.
React is a library designed specifically for creating
user interfaces.
For routing, data fetching etc.. you have to install
other libraries
Next.js
Next.js uses React for building user interfaces.
Next.js has additional tools that allow you to build applications that are ready
for production.
Next.js
Next.js uses React for building user interfaces.
Next.js has additional tools that allow you to build applications that are ready
for production.
Routing, Optimized Rendering, Data Fetchihg, Bundling, Compiling and more
Next.js
Next.js uses React for building user interfaces.
Next.js has additional tools that allow you to build applications that are ready
for production.
Routing, Optimized Rendering, Data Fetchihg, Bundling, Compiling and more
We do not have to install any additional packages for that.
Next.js
Next.js uses React for building user interfaces.
Next.js has additional tools that allow you to build applications that are ready
for production.
Routing, Optimized Rendering, Data Fetchihg, Bundling, Compiling and more
We do not have to install any additional packages for that.
To achieve these features you have to follow convention
Next.js makes it easier to build production-ready web applications.
1. Routing
Next.js makes it easier to build production-ready web applications.
1. Routing
2. API Routing
Next.js makes it easier to build production-ready web applications.
1. Routing
2. API Routing
3. Rendering
Next.js makes it easier to build production-ready web applications.
1. Routing
2. API Routing
3. Rendering
4. Data Fetching
Next.js makes it easier to build production-ready web applications.
1. Routing
2. API Routing
3. Rendering
4. Data Fetching
5. Styling
Next.js makes it easier to build production-ready web applications.
1. Routing
2. API Routing
3. Rendering
4. Data Fetching
5. Styling
5. Optimization
Next.js makes it easier to build production-ready web applications.
1. Routing
2. API Routing
3. Rendering
4. Data Fetching
5. Styling
5. Optimization
5. Dev and prod build system
Next.js makes it easier to build production-ready web applications.
1. Routing
2. API Routing
3. Rendering
4. Data Fetching
5. Styling
5. Optimization
5. Dev and prod build system
HTML
HTML
CSS
HTML
CSS
JavaScript
HTML
CSS
JavaScript
React.js Fundamentals
HTML
CSS
JavaScript
React.js Fundamentals
React Team introduced a new architecture called React Server Component (RSC) and Next.js quickly adopted it.
React Team introduced a new architecture called React Server Component (RSC) and Next.js quickly adopted it.
This architecture offers a fresh way of building React components by categorizing them into two distinct types.
React Team introduced a new architecture called React Server Component (RSC) and Next.js quickly adopted it.
This architecture offers a fresh way of building React components by categorizing them into two distinct types.
2. Client Component
1. Server Component
Server Component
By default, Next.js considers all components to be server components.
Server Component
By default, Next.js considers all components to be server components.
These components can perform server-side tasks like reading files or fetching data directly from a database.
Server Component
By default, Next.js considers all components to be server components.
These components can perform server-side tasks like reading files or fetching data directly from a database.
GSAP & Next.js 15 : The Complete GSAP Masterclass for Beginners in Hindi
Client Component
To create a client component in Next.js we have to use "use client" directive at the top of your component file.
Client Component
To create a client component in Next.js we have to use "use client" directive at the top of your component file.
Client component can not perform server-side tasks like reading files, but we can use hooks and handle user interaction.
Client Component
To create a client component in Next.js we have to use "use client" directive at the top of your component file.
Client component can not perform server-side tasks like reading files, but we can use hooks and handle user interaction.
Client component same as we create a component in react.js
Next.js has a file-system based routing system
All routes must live inside the app folder
All routes must live inside the app folder
Route files must be named either page.js or page.tsx
All routes must live inside the app folder
Route files must be named either page.js or page.tsx
If we follow these conventions, the file automatically becomes
available as a route
Text
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
http://localhost:3000
Text
Home Page
Text
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
http://localhost:3000/about
About Page
Text
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
http://localhost:3000/contact
Contact Page
Text
Text
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
product
page.tsx
Products
Product 1
Product 2
Product 3
Product 4
Product 5
Product 6
Product 7
Product 8
Product 9
http://localhost:3000/product
[productId]
page.tsx
Products Details
Product
http://localhost:3000/product/productId
Product Title
Category: ABC
Price: $1234
About this item
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Add to Cart
Buy Now
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
product
page.tsx
[productId]
page.tsx
Products Details
Product
http://localhost:3000/product/1234
Product Title
Category: ABC
Price: $1234
About this item
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Add to Cart
Buy Now
Reviews
Naina
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Mohit
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
More...
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
product
page.tsx
[productId]
page.tsx
Products
Product 1
Product 2
Product 3
Product 4
Product 5
Product 6
Product 7
Product 8
Product 9
http://localhost:3000/product
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
product
page.tsx
[productId]
page.tsx
Products Details
Product
http://localhost:3000/product/1234
Product Title
Category: ABC
Price: $1234
About this item
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Add to Cart
Buy Now
Reviews
Naina
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Mohit
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
More...
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
product
page.tsx
[productId]
page.tsx
reviews
page.tsx
[reviewId]
Reviews
http://localhost:3000/product/1234/1
Naina
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
product
page.tsx
[productId]
page.tsx
reviews
page.tsx
[reviewId]
Math Lecture
Physics Lecture
Chemistry Lecture
Text
Lectures
Text
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
product
page.tsx
[productId]
page.tsx
lectures
[...slug]
page.tsx
http://localhost:3000/lectures/lecture1
Text
Text
Text
That folder and subfolders are excluded from routing
Text
Text
That folder and subfolders are excluded from routing
Add and underscore ( _ ) at the begning of your folder name
Text
Text
That folder and subfolders are excluded from routing
Add and underscore ( _ ) at the begning of your folder name
Even if you have page.tsx inside folder with default export it will not route.
_my-folder
Text
app
about
page.tsx
contact
page.tsx
layout.tsx
page.tsx
product
page.tsx
[productId]
page.tsx
lectures
[...slug]
page.tsx
http://localhost:3000/lectures/lecture1/sub-lecture1
Text
Text
This helps in organizing routes and project files in a logical way while keeping the URL structure intact.
Text
This helps in organizing routes and project files in a logical way while keeping the URL structure intact.
We will Create
- Register
- Login
Text
Text
Layout is UI component where all your routes render as children.
Text
Layout is UI component where all your routes render as children.
Whatever code you write in your layout will share all those routes
which is rendering on that layout
Text
Text
We have to create layout.tsx or layout.js file
Text
We have to create layout.tsx or layout.js file
That component takes children prop, and children are nothing but
your route page.
Text
app
about
contact
layout.tsx
page.tsx
product
lectures
app
about
contact
layout.tsx
page.tsx
product
lectures
Use of Route Group
Use of Route Group
We can organize our project in a batter way without affecting URLs
Use of Route Group
We can organize our project in a batter way without affecting URLs
We can also apply layout specific modules/part of our application.
Metadata plays a crucial role in enhancing SEO and improving web shareability by providing essential information about your web pages.
Metadata plays a crucial role in enhancing SEO and improving web shareability by providing essential information about your web pages.
We have two ways to add Metadata in next.js
Metadata plays a crucial role in enhancing SEO and improving web shareability by providing essential information about your web pages.
We have two ways to add Metadata in next.js
1. Static Metadata
Metadata plays a crucial role in enhancing SEO and improving web shareability by providing essential information about your web pages.
We have two ways to add Metadata in next.js
1. Static Metadata
2. Dynamic Metadata
Metadata plays a crucial role in enhancing SEO and improving web shareability by providing essential information about your web pages.
We have two ways to add Metadata in next.js
1. Static Metadata
We can add this metadata export in page.tsx or in layout.tsx
Metadata plays a crucial role in enhancing SEO and improving web shareability by providing essential information about your web pages.
We have two ways to add Metadata in next.js
2. Dynamic Metadata
We can add this metadata export in page.tsx or in layout.tsx
Special File
This helps you create meaningful Loading UI with React Suspense
This helps you create meaningful Loading UI with React Suspense
You can show an instant loading state from the server while the content of a route takes time to load.
This helps you create meaningful Loading UI with React Suspense
You can show an instant loading state from the server while the content of a route takes time to load.
To create loading in Next.js we have to create a file loading.tsx or loading.js
This helps you create meaningful Loading UI with React Suspense
You can show an instant loading state from the server while the content of a route takes time to load.
To create loading in Next.js we have to create a file loading.tsx or loading.js
Special File
This allows you to handle unexpected runtime errors and display fallback UI
This allows you to handle unexpected runtime errors and display fallback UI
To handle errors we can create an error file with the name error.tsx or error.js
This allows you to handle unexpected runtime errors and display fallback UI
To handle errors we can create an error file with the name error.tsx or error.js
This wraps a route segment and its nested children in a React Error Boundary
This allows you to handle unexpected runtime errors and display fallback UI
To handle errors we can create an error file with the name error.tsx or error.js
This wraps a route segment and its nested children in a React Error Boundary
What is Paralel Routes ?
What is Paralel Routes ?
With Parallel Routes, you can render one or more pages simultaneously
or conditions, all within the same layout
Charts
Line Chart
Bar Chart
Heatmap
app
about
contact
layout.tsx
page.tsx
product
charts
line-chart
bar-chart
heatmap
layout.tsx
How to Setup Parallel Routes ?
How to Setup Parallel Routes ?
Parallel routes are created using named slots.
How to Setup Parallel Routes ?
Parallel routes are created using named slots.
Slots are defined with the @folder convention.
How to Setup Parallel Routes ?
Parallel routes are created using named slots.
Slots are defined with the @folder convention.
Each defined slot automatically becomes props in corresponding layout.tsx file
app
about
contact
layout.tsx
page.tsx
product
charts
@line-chart
@bar-chart
@heatmap
layout.tsx
page.tsx
page.tsx
page.tsx
Charts
Line Chart
Bar Chart
Heatmap
Parallel Routes benefits?
Parallel Routes benefits?
It is very useful for highly dynamic sections of an app, such as dashboards and feeds on social sites.
Parallel Routes benefits?
It is very useful for highly dynamic sections of an app, such as dashboards and feeds on social sites.
Independent route handling
Parallel Routes benefits?
It is very useful for highly dynamic sections of an app, such as dashboards and feeds on social sites.
Independent route handling
Sub-navigation
Independent route handling
Independent route handling
Each slot can have its own loading and error states.
Independent route handling
Each slot can have its own loading and error states.
This is very useful when you want to handle loading and error separately for each slot.
Independent route handling
Each slot can have its own loading and error states.
This is very useful when you want to handle loading and error separately for each slot.
Charts
Line Chart
Heatmap
Independent route handling
Each slot can have its own loading and error states.
This is very useful when you want to handle loading and error separately for each slot.
Charts
Line Chart
Error loading heatmap
Sub-navigation
Sub-navigation
Each can work as mini application
Sub-navigation
Each can work as mini application
We can work with each separately like, apply filters, sorting or navigation without effecting any other pages or slot
Sub-navigation
Each can work as mini application
We can work with each separately like, apply filters, sorting or navigation without effecting any other pages or slot
Charts
Line Chart
Bar Chart
Heatmap
Pie chart
Navigation from UI
Navigation from UI
When you navigate through the UI Next.js keep showing whatever was in the
unmatch slots before
Navigation from UI
When you navigate through the UI Next.js keep showing whatever was in the
unmatch slots before
Page Reload
Navigation from UI
When you navigate through the UI Next.js keep showing whatever was in the
unmatch slots before
Page Reload
Next.js looks for a 'default.tsx' file in each unmatch slot
Navigation from UI
When you navigate through the UI Next.js keep showing whatever was in the
unmatch slots before
Page Reload
Next.js looks for a 'default.tsx' file in each unmatch slot
This file is critical as it serves as a fallback to render content when the framework cannot reterive a slot's active state from the current URL
Navigation from UI
When you navigate through the UI Next.js keep showing whatever was in the
unmatch slots before
Page Reload
Next.js looks for a 'default.tsx' file in each unmatch slot
This file is critical as it serves as a fallback to render content when the framework cannot reterive a slot's active state from the current URL
Without default.tsx file you will get 404 error.
1. Parallel Routes
1. Parallel Routes
2. Intercepting Routes
http://localhost:3000/
Login
Logo
http://localhost:3000/login
http://localhost:3000/login
Login
Logo
Click
Share
(.) to match segments on the same level
(.) to match segments on the same level
(..) to match segments one level above
(.) to match segments on the same level
(..) to match segments one level above
(..)(..) to match segments on two levels above
(.) to match segments on the same level
(..) to match segments one level above
(..)(..) to match segments on two levels above
(...) to match segments from the root app directory
Using app router we can create custom request handlers for your routes using a feature called Route Handlers
Using app router we can create custom request handlers for your routes using a feature called Route Handlers
Page routes are used to serve HTML content, whereas Route Handlers empower us to build RESTful endpoints with total control over the response
Using app router we can create custom request handlers for your routes using a feature called Route Handlers
Page routes are used to serve HTML content, whereas Route Handlers empower us to build RESTful endpoints with total control over the response
As we build RESTful APIs using Node and Express, we can do all CRUD operations
with Route Handlers
Using app router we can create custom request handlers for your routes using a feature called Route Handlers
Page routes are used to serve HTML content, whereas Route Handlers empower us to build RESTful endpoints with total control over the response
As we build RESTful APIs using Node and Express, we can do all CRUD operations
with Route Handlers
And we don't need to configure separate server.
Using app router we can create custom request handlers for your routes using a feature called Route Handlers
Page routes are used to serve HTML content, whereas Route Handlers empower us to build RESTful endpoints with total control over the response
As we build RESTful APIs using Node and Express, we can do all CRUD operations
with Route Handlers
And we don't need to configure separate server.
In Route handlers, we can also make external API requests. like if we need to talk with third-party services.
Using app router we can create custom request handlers for your routes using a feature called Route Handlers
Page routes are used to serve HTML content, whereas Route Handlers empower us to build RESTful endpoints with total control over the response
As we build RESTful APIs using Node and Express, we can do all CRUD operations
with Route Handlers
And we don't need to configure separate server.
In Route handlers, we can also make external API requests. like if we need to talk with third-party services.
Since route handlers run on the server side, sensitive data like private keys are kept safe.
Using app router we can create custom request handlers for your routes using a feature called Route Handlers
Page routes are used to serve HTML content, whereas Route Handlers empower us to build RESTful endpoints with total control over the response
As we build RESTful APIs using Node and Express, we can do all CRUD operations
with Route Handlers
And we don't need to configure separate server.
In Route handlers, we can also make external API requests. like if we need to talk with third-party services.
Since route handlers run on the server side, sensitive data like private keys are kept safe.
Route handlers are equvelant to API routes.
Using app router we can create custom request handlers for your routes using a feature called Route Handlers
Page routes are used to serve HTML content, whereas Route Handlers empower us to build RESTful endpoints with total control over the response
As we build RESTful APIs using Node and Express, we can do all CRUD operations
with Route Handlers
And we don't need to configure separate server.
In Route handlers, we can also make external API requests. like if we need to talk with third-party services.
Since route handlers run on the server side, sensitive data like private keys are kept safe.
Route handlers are equvelant to API routes.
Next.js supports GET, POST, PUT, PATCH, DELETE, HEAD, AND OPTIONS
Next.js will return a 405 Method Not Allowed response when an unsupported method is used
HTTP headers provide information about the metadata of an API request
and its response.
HTTP headers provide information about the metadata of an API request
and its response.
Request Headers
HTTP headers provide information about the metadata of an API request
and its response.
Request Headers
These are sent by the clients, such as a web browser, to the server. They contain essential information about the request, which helps the server understand and process it correctly
HTTP headers provide information about the metadata of an API request
and its response.
Request Headers
These are sent by the clients, such as a web browser, to the server. They contain essential information about the request, which helps the server understand and process it correctly
"User-Agent"
They indicate details about the server's browser and operating system
HTTP headers provide information about the metadata of an API request
and its response.
Request Headers
These are sent by the clients, such as a web browser, to the server. They contain essential information about the request, which helps the server understand and process it correctly
"User-Agent"
They indicate details about the server's browser and operating system
"Accept"
They indicate the types of content, like text, video, or image formats, that the client can handle
HTTP headers provide information about the metadata of an API request
and its response.
Request Headers
These are sent by the clients, such as a web browser, to the server. They contain essential information about the request, which helps the server understand and process it correctly
"Authorization"
enables the client to provide authentication credentials to the server.
"User-Agent"
They indicate details about the server's browser and operating system
"Accept"
They indicate the types of content, like text, video, or image formats, that the client can handle
HTTP headers provide information about the metadata of an API request
and its response.
Response Headers
HTTP headers provide information about the metadata of an API request
and its response.
Response Headers
These are sent back from the server to the client. They provide information about the server and the data being sent in the response.
HTTP headers provide information about the metadata of an API request
and its response.
Response Headers
These are sent back from the server to the client. They provide information about the server and the data being sent in the response.
"Content-Type"
header which indicates the media type of the response. it tells the client what the data type of the returned content is, such as text/html or HTML documents,
application/json for JSON data. etc.
HTTP headers provide information about the metadata of an API request
and its response.
Response Headers
These are sent back from the server to the client. They provide information about the server and the data being sent in the response.
"Content-Type"
header which indicates the media type of the response. it tells the client what the data type of the returned content is, such as text/html or HTML documents,
application/json for JSON data. etc.
Cookies are small pieces data that server send to your browser to identify you and remember your preferences
Cookies are small pieces data that server send to your browser to identify you and remember your preferences
Your browser can store the cookies and send them back to the server whenever you
request the server again
Cookies are small pieces data that server send to your browser to identify you and remember your preferences
Your browser can store the cookies and send them back to the server whenever you
request the server again
Use of Cookies ?
Cookies are small pieces data that server send to your browser to identify you and remember your preferences
Your browser can store the cookies and send them back to the server whenever you
request the server again
Use of Cookies ?
User Authentication: To identify users and maintain logged-in sessions.
Cookies are small pieces data that server send to your browser to identify you and remember your preferences
Your browser can store the cookies and send them back to the server whenever you
request the server again
Use of Cookies ?
User Authentication: To identify users and maintain logged-in sessions.
User Preferences: To remember user-specific settings and preferences
Cookies are small pieces data that server send to your browser to identify you and remember your preferences
Your browser can store the cookies and send them back to the server whenever you
request the server again
Use of Cookies ?
User Authentication: To identify users and maintain logged-in sessions.
User Preferences: To remember user-specific settings and preferences
Session Management: To keep track of active sessions for users.
By default, route handlers are not cached; however, caching can be enabled when using the get method.
By default, route handlers are not cached; however, caching can be enabled when using the get method.
Caching only work with get method
By default, route handlers are not cached; however, caching can be enabled when using the get method.
Caching only work with get method
Methods like POST, PUT, or DELETE in HTTP are never cached.
By default, route handlers are not cached; however, caching can be enabled when using the get method.
Caching only work with get method
Methods like POST, PUT, or DELETE in HTTP are never cached.
Caching will not work if you are using dynamic functions like headers() and cookies() or working with the request object in your GET method.
In Next.js, middleware provides a powerful way to intercept and control how requests and responses are handled across your application.
In Next.js, middleware provides a powerful way to intercept and control how requests and responses are handled across your application.
It operates globally, boosting capabilities such as redirects, URL rewrites, authentication, managing headers, cookies, and much more.
In Next.js, middleware provides a powerful way to intercept and control how requests and responses are handled across your application.
It operates globally, boosting capabilities such as redirects, URL rewrites, authentication, managing headers, cookies, and much more.
Middleware allows you to define specific paths where it should be applied.
In Next.js, middleware provides a powerful way to intercept and control how requests and responses are handled across your application.
It operates globally, boosting capabilities such as redirects, URL rewrites, authentication, managing headers, cookies, and much more.
Middleware allows you to define specific paths where it should be applied.
- Custom matcher config
In Next.js, middleware provides a powerful way to intercept and control how requests and responses are handled across your application.
It operates globally, boosting capabilities such as redirects, URL rewrites, authentication, managing headers, cookies, and much more.
Middleware allows you to define specific paths where it should be applied.
- Custom matcher config
- Conditional Statements
It is the process of transforming the code that you write into user interfaces so that users can see and interact with it.
It is the process of transforming the code that you write into user interfaces so that users can see and interact with it.
In Next.js the tricky part to building a performant application is figuring out when and where this transformation should happen
It is the process of transforming the code that you write into user interfaces so that users can see and interact with it.
In Next.js the tricky part to building a performant application is figuring out when and where this transformation should happen
CSR, SSR and RSCs?
It is the process of transforming the code that you write into user interfaces so that users can see and interact with it.
In Next.js the tricky part to building a performant application is figuring out when and where this transformation should happen
CSR, SSR and RSCs?
Before we go deep into rendering let's look how rendering work in React.
It is the process of transforming the code that you write into user interfaces so that users can see and interact with it.
In Next.js the tricky part to building a performant application is figuring out when and where this transformation should happen
CSR, SSR and RSCs?
Before we go deep into rendering let's look how rendering work in React.
Next.js build on top of React if we understand how rendering work in React we will understand rendering very well.
We will look at how React's rendering has transformed over the past years.
We will dive into React different rendering strategies and see
how they change over time.
We will look at how React's rendering has transformed over the past years.
If you have worked with React so long you may remember that React is primarily used for building Single Page Applications (SPAs)
We will dive into React different rendering strategies and see
how they change over time.
We will look at how React's rendering has transformed over the past years.
Client
Server
Client
Server
Client Request to Server
Client
Server
Client Request to Server
Blank Screen
HTML with JavaScript Refrence
Client
Server
Client Request to Server
Blank Screen
HTML with JavaScript Refrence
Request JavaScript
Client
Server
Client Request to Server
Blank Screen
HTML with JavaScript Refrence
Request JavaScript
JavaScript
Client
Server
Client Request to Server
Blank Screen
HTML with JavaScript Refrence
Request JavaScript
JavaScript
Generate HTML
Client
Server
Client Request to Server
Blank Screen
Interactive UI
APP
HTML with JavaScript Refrence
Request JavaScript
JavaScript
Generate HTML
The whole approach we have seen - where your browser (client) transforms React code into what you see on the screen - that's what we call client-side rendering (CSR)
The whole approach we have seen - where your browser (client) transforms React code into what you see on the screen - that's what we call client-side rendering (CSR)
CSR became very popular for SPAs applications, and everyone was using it.
The whole approach we have seen - where your browser (client) transforms React code into what you see on the screen - that's what we call client-side rendering (CSR)
CSR became very popular for SPAs applications, and everyone was using it.
Developers after using CSR noticing drawbacks in to this approach.
SEO
SEO
When search engines crawl your site, they're mainly looking at HTML content. But with CSR, your initial HTML is basically just an empty div - it is not good for SEO because search engines will not be able to figure out about the page.
SEO
When search engines crawl your site, they're mainly looking at HTML content. But with CSR, your initial HTML is basically just an empty div - it is not good for SEO because search engines will not be able to figure out about the page.
When you have many nested components and making API calls, content of your pages will load might slowly for search engines to even catch it.
Performance
If you notice your browser (client) has to do everything with this approach: fetch data, build the UI, make everything interactive... that's a lot of work!
Performance
If you notice your browser (client) has to do everything with this approach: fetch data, build the UI, make everything interactive... that's a lot of work!
If you notice your browser (client) has to do everything with this approach: fetch data, build the UI, make everything interactive... that's a lot of work!
With this approach (CSR), Users often end up staring at a blank screen or a loading spinner while all this happens
Performance
If you notice your browser (client) has to do everything with this approach: fetch data, build the UI, make everything interactive... that's a lot of work!
If you notice your browser (client) has to do everything with this approach: fetch data, build the UI, make everything interactive... that's a lot of work!
With this approach (CSR), Users often end up staring at a blank screen or a loading spinner while all this happens
Whenever you add new features or modules to your application, that JavaScript bundle gets bigger, and it will make users wait even longer.
Performance
If you notice your browser (client) has to do everything with this approach: fetch data, build the UI, make everything interactive... that's a lot of work!
If you notice your browser (client) has to do everything with this approach: fetch data, build the UI, make everything interactive... that's a lot of work!
With this approach (CSR), Users often end up staring at a blank screen or a loading spinner while all this happens
Whenever you add new features or modules to your application, that JavaScript bundle gets bigger, and it will make users wait even longer.
If users have slower internet user will be frustrated with this.
Developer need batter solution for SEO and Performance we will see up Next.
With CSR we have two drawbacks SEO and Performance
With CSR we have two drawbacks SEO and Performance
Modern framework like Next.js move to server-side solutions
With CSR we have two drawbacks SEO and Performance
Modern framework like Next.js move to server-side solutions
We will see how Server-side improve this
Client
Server
Client
Server
Client Request to Server
Client
Server
Client Request to Server
Generate HTML
Client
Server
Client Request to Server
FullHTML with JavaScript Refrence
Generate HTML
User Can not Interact with UI
Client
Server
Client Request to Server
Request JavaScript
Generate HTML
User Can not Interact with UI
FullHTML with JavaScript Refrence
Client
Server
Client Request to Server
Request JavaScript
JavaScript
Generate HTML
FullHTML with JavaScript Refrence
User Can not Interact with UI
Client
Server
Client Request to Server
Request JavaScript
JavaScript
Hydration
Generate HTML
FullHTML with JavaScript Refrence
User Can not Interact with UI
Client
Server
Client Request to Server
Interactive UI
APP
Request JavaScript
JavaScript
Hydration
Generate HTML
FullHTML with JavaScript Refrence
User Can not Interact with UI
With this approach, Search engines can now easily index the server-rendered content, and it will solve our SEO problem.
With this approach, Search engines can now easily index the server-rendered content, and it will solve our SEO problem.
Now server sends HTML so users see actual HTML content right away instead blank screen or loading a spinner
With this approach, Search engines can now easily index the server-rendered content, and it will solve our SEO problem.
Now server sends HTML so users see actual HTML content right away instead blank screen or loading a spinner
Now SSR makes content visible faster but it also introduces its drawbacks.
With this approach, Search engines can now easily index the server-rendered content, and it will solve our SEO problem.
Now server sends HTML so users see actual HTML content right away instead blank screen or loading a spinner
Now SSR makes content visible faster but it also introduces its drawbacks.
HTML Page can not become fully interactive before the HTML and js bundle are fully downloaded and executed in the browser.
With this approach, Search engines can now easily index the server-rendered content, and it will solve our SEO problem.
Now server sends HTML so users see actual HTML content right away instead blank screen or loading a spinner
Now SSR makes content visible faster but it also introduces its drawbacks.
HTML Page can not become fully interactive before the HTML and js bundle are fully downloaded and executed in the browser.
This important face known as Hydration
While Hydration, React takes control in the browser and reconstructs our component tree in the memory, using the server-rendered HTML as a blueprint.
While Hydration, React takes control in the browser and reconstructs our component tree in the memory, using the server-rendered HTML as a blueprint.
It precisely maps where all the interactive elements should go, and then add the JavaScript logics.
While Hydration, React takes control in the browser and reconstructs our component tree in the memory, using the server-rendered HTML as a blueprint.
It precisely maps where all the interactive elements should go, and then add the JavaScript logics.
Like initializing the application state, adding events like click and mouseover, and setting up all the dynamic features needed for a fully interactive user experience.
This is categories in two main categories.
This is categories in two main categories.
1. Static Site Generation (SSG)
2. Server-side Rendering (SSR)
1. Static Site Generation (SSG)
Static Site Generation happens during build time when you deploy your
application to the server
1. Static Site Generation (SSG)
Static Site Generation happens during build time when you deploy your
application to the server
It means when you request to the server the SSG page will immediately
be sent to the client
1. Static Site Generation (SSG)
Static Site Generation happens during build time when you deploy your
application to the server
It means when you request to the server the SSG page will immediately
be sent to the client
We can use SSG with blog post
2. Server-side Rendering (SSR)
Server-side Rendering renders the pages when you request the server.
2. Server-side Rendering (SSR)
Server-side Rendering renders the pages when you request the server.
It is beneficial for personalized content like social media feeds where HTML changes based on user login.
2. Server-side Rendering (SSR)
Server-side Rendering renders the pages when you request the server.
It is beneficial for personalized content like social media feeds where HTML changes based on user login.
We have seen how rendering improves with CSR to SSR.
But SSR also has its challenges.
You have to fetch everything before you can show anything
You have to fetch everything before you can show anything
Your component will not start rendering and then pause or "wait" while
data is still being loaded
You have to fetch everything before you can show anything
Your component will not start rendering and then pause or "wait" while
data is still being loaded
If you are fetching data from a database in a component or any other sources (like third-party API), the fetching of the data must be completed before
the server can begin rendering the component
You have to fetch everything before you can show anything
Your component will not start rendering and then pause or "wait" while
data is still being loaded
If you are fetching data from a database in a component or any other sources (like third-party API), the fetching of the data must be completed before
the server can begin rendering the component.
While data fetching and rendering this process can delay the server's response
time to the browser.
You have to fetch everything before you can show anything
Your component will not start rendering and then pause or "wait" while
data is still being loaded
If you are fetching data from a database in a component or any other sources (like third-party API), the fetching of the data must be completed before
the server can begin rendering the component.
While data fetching and rendering this process can delay the server's response
time to the browser.
It will be delayed because the server must need to finish the collection of all necessary data before sending any part of the page to the client.
You have to load everything before you can hydrate anything
You have to load everything before you can hydrate anything
To achieve successful hydration, where React adds interactivity to the server-rendered HTML, your component tree in the browser must exactly match
the server-generated component tree.
You have to load everything before you can hydrate anything
To achieve successful hydration, where React adds interactivity to the server-rendered HTML, your component tree in the browser must exactly match
the server-generated component tree.
This means that all the JavaScript for the components must be loaded on the client before you can start hydrating any of them.
You can not interact with anything Before hydration
You can not interact with anything Before hydration
React performs hydration in a single pass, processing the entire component tree from start to finish without interruption.
You can not interact with anything Before hydration
React performs hydration in a single pass, processing the entire component tree from start to finish without interruption.
This means that every component must undergo hydration before it becomes interactive.
Load data for entire page.
Load the JS for entire pages
Hydrate the entire page
Load data for entire page.
Load the JS for entire pages
Hydrate the entire page
This is very problematic when some parts of pages take time to load.
Load data for entire page.
Load the JS for entire pages
Hydrate the entire page
This is very problematic when some parts of pages take time to load.
Because of these problems React Team develop new improved SSR Architecture.
You can not interact with anything Before hydration
You have to load everything before you can hydrate anything
You have to fetch everything before you can show anything
You can not interact with anything Before hydration
You have to load everything before you can hydrate anything
You have to fetch everything before you can show anything
Because of these problems React Team develop new improved SSR Architecture.
In Suspense SSR architecture React Team introduced a new Component
called <Suspense>
In Suspense SSR architecture React Team introduced a new Component
called <Suspense>
With Suspense, it unlocks two major features.
In Suspense SSR architecture React Team introduced a new Component
called <Suspense>
With Suspense, it unlocks two major features.
1. HTML Streaming on the server
2. Selective hydration on the client
Client
Server
Client
Server
Client Request to Server
Generate HTML
Client
Server
Client Request to Server
Generate HTML
FullHTML with JavaScript Refrence
Client
Server
Client Request to Server
Request JavaScript
Generate HTML
FullHTML with JavaScript Refrence
User Can not Interact with UI
Client
Server
Client Request to Server
Request JavaScript
JavaScript
Generate HTML
FullHTML with JavaScript Refrence
User Can not Interact with UI
Client
Server
Client Request to Server
Request JavaScript
JavaScript
Hydration
Generate HTML
FullHTML with JavaScript Refrence
User Can not Interact with UI
Client
Server
Client Request to Server
Interactive UI
APP
Request JavaScript
JavaScript
Hydration
Generate HTML
FullHTML with JavaScript Refrence
User Can not Interact with UI
Text
Render
Text
Header
Banner
Footer
Text
Header
Banner
Footer
Main
Text
HTML streaming on the server
HTML streaming on the server
With this approach, you don't have to fetch everything before you can show anything
HTML streaming on the server
With this approach, you don't have to fetch everything before you can show anything
If any of section taking time in load other sections will load immidiatly.
HTML streaming on the server
With this approach, you don't have to fetch everything before you can show anything
If any of section taking time in load other sections will load immidiatly.
It can be seamlessly integrated into the stream later when it's ready
We know HTML will download faster, but until it loads all JavaScript for the main section it will not start hydrating.
We know HTML will download faster, but until it loads all JavaScript for the main section it will not start hydrating.
If we have a big chunk of code, the user will still have to wait to interact with the page.
with this, it will tell your bundler, "These parts of the code arn't urgent - split them into separate scripts."
with this, it will tell your bundler, "These parts of the code arn't urgent - split them into separate scripts."
If we use "React.lazy" for code splitting it will separates your main section's code from the core JavaScript bundle
with this, it will tell your bundler, "These parts of the code arn't urgent - split them into separate scripts."
If we use "React.lazy" for code splitting it will separates your main section's code from the core JavaScript bundle
This means if the main sections take time to load browser can download React and most of your app's code independently.
When you wrap your main section with the <Suspense> component, it is not just enables streaming but also tells React to hydrate other parts of the page before everything ready.
When you wrap your main section with the <Suspense> component, it is not just enables streaming but also tells React to hydrate other parts of the page before everything ready.
This is called Selective Hydration
Header
Banner
Footer
Main
Header
Banner
Footer
Main
Selective Hydration also solves the third problem: the necessary to "hydrate everything to interact with anything"
Selective Hydration also solves the third problem: the necessary to "hydrate everything to interact with anything"
React will start hydrating as soon as it can, which means users can interact with the other part of the page if some part of the page taking time to load.
Selective Hydration also solves the third problem: the necessary to "hydrate everything to interact with anything"
React will start hydrating as soon as it can, which means users can interact with the other part of the page if some part of the page taking time to load.
React also prioritises hydration based on user interaction.
Header
Banner
Footer
Blogs
Social Feed
Header
Banner
Footer
Blogs
Social Feed
Header
Banner
Footer
Blogs
Social Feed
Data fetching must be completed before the server can begin rendering HTML
Required JavaScript for the components need to be fully loaded on the client side before the hydration process can start.
All components have to hydrate before becoming interactive.
Even though we're streaming JavaScript code to the browser bit by bit, eventually users still end up downloading the entire code for a webpage.
1
When we add more features or modules to our app the code will more larger.
Even though we're streaming JavaScript code to the browser bit by bit, eventually users still end up downloading the entire code for a webpage.
1
Do We need to downlaod so much data?
When we add more features or modules to our app the code will more larger.
Even though we're streaming JavaScript code to the browser bit by bit, eventually users still end up downloading the entire code for a webpage.
1
If you see every React component hydrated on the client side,
whether it needs interactivity or not
2
If you see every React component hydrated on the client side,
whether it needs interactivity or not
2
This means we are using many resources and slowing down load time to interactivity by hydrating that might just be static components.
If you see every React component hydrated on the client side,
whether it needs interactivity or not
2
This means we are using many resources and slowing down load time to interactivity by hydrating that might just be static components.
Now we have another question
If you see every React component hydrated on the client side,
whether it needs interactivity or not
2
This means we are using many resources and slowing down load time to interactivity by hydrating that might just be static components.
Now we have another question
Should all components be hydrated, even those that don't need interactivity?
If you think your server is better to handle heavy processing, but we are still making user devices do the bulk of JavaScript work.
3
If you think your server is better to handle heavy processing, but we are still making user devices do the bulk of JavaScript work.
3
This will slow things down if user devices are not powerful.
If you think your server is better to handle heavy processing, but we are still making user devices do the bulk of JavaScript work.
3
This will slow things down if user devices are not powerful.
Now we have another important question
If you think your server is better to handle heavy processing, but we are still making user devices do the bulk of JavaScript work.
3
This will slow things down if user devices are not powerful.
Now we have another important question
Shouldn't we be using our servers more?
CSR > SSR > Suspense for SSR
CSR > SSR > Suspense for SSR
Suspense for SSR solve meany problem but also left some challenges.
CSR > SSR > Suspense for SSR
CSR > SSR > Suspense for SSR
CSR > SSR > Suspense for SSR
Large bundle sizes causing excessive downloads for users
Suspense for SSR solve meany problem but also left some challenges.
CSR > SSR > Suspense for SSR
CSR > SSR > Suspense for SSR
Large bundle sizes causing excessive downloads for users
Unnessary hydration delay interactivity
Suspense for SSR solve meany problem but also left some challenges.
CSR > SSR > Suspense for SSR
CSR > SSR > Suspense for SSR
Large bundle sizes causing excessive downloads for users
Unnessary hydration delay interactivity
Suspense for SSR solve meany problem but also left some challenges.
Heavy client-side processing leads to poor performance.
This is a new design architecture by the React Team called React Server Components (RSC)
This is a new design architecture by the React Team called React Server Components (RSC)
With this approach, we can create server and client components to optimize efficiency,
load times, and interactivity.
This is a new design architecture by the React Team called React Server Components (RSC)
With this approach, we can create server and client components to optimize efficiency,
load times, and interactivity.
With RSC architecture we can create component with two ways.
This is a new design architecture by the React Team called React Server Components (RSC)
With this approach, we can create server and client components to optimize efficiency,
load times, and interactivity.
With RSC architecture we can create component with two ways.
1. Client Component
2. Server Component
Client components are similar to normal React components that we already using.
Client components are similar to normal React components that we already using.
Client component rendered on the client-side (CSR) but, it can also be render to
HTML on the server (SSR)
Client components are similar to normal React components that we already using.
Client component rendered on the client-side (CSR) but, it can also be render to
HTML on the server (SSR)
This means the user will not see the blank screen and will see HTML content immediately because it is rendered on the server.
Client components are similar to normal React components that we already using.
Client component rendered on the client-side (CSR) but, it can also be render to
HTML on the server (SSR)
This means the user will not see the blank screen and will see HTML content immediately because it is rendered on the server.
Client components mainly function on the client but can, and ideally should, run once on the server to enhance performance.
Client components are similar to normal React components that we already using.
Client component rendered on the client-side (CSR) but, it can also be render to
HTML on the server (SSR)
This means the user will not see the blank screen and will see HTML content immediately because it is rendered on the server.
Client components mainly function on the client but can, and ideally should, run once on the server to enhance performance.
Client components have complete access to the client environment, including the browser, enabling them to utilize state, effects, and event listeners to manage interactivity.
Client components are similar to normal React components that we already using.
Client component rendered on the client-side (CSR) but, it can also be render to
HTML on the server (SSR)
This means the user will not see the blank screen and will see HTML content immediately because it is rendered on the server.
Client components mainly function on the client but can, and ideally should, run once on the server to enhance performance.
Client components have complete access to the client environment, including the browser, enabling them to utilize state, effects, and event listeners to manage interactivity.
Client components can also access browser APIs like geolocation or storage allowing you to build UI for your use cases.
Server components introduce a new type of React component specifically meant for
server-side operation only.
Server components introduce a new type of React component specifically meant for
server-side operation only.
Client components code is downloaded to the client whereas Server components stay on the server and are never downloaded to the client.
Server components introduce a new type of React component specifically meant for
server-side operation only.
Client components code is downloaded to the client whereas Server components stay on the server and are never downloaded to the client.
This Server and Client Components offer multiple benefits to our React applications.
App Bundle Size Smaller
App Bundle Size Smaller
Server components introduce a new type of React component specifically meant for
server-side operation only.
App Bundle Size Smaller
Server components introduce a new type of React component specifically meant for
server-side operation only.
Now if any user has slower connections or less powerful devices, they don't need to download, parse, and execute the JavaScript.
App Bundle Size Smaller
Server components introduce a new type of React component specifically meant for
server-side operation only.
Now if any user has slower connections or less powerful devices, they don't need to download, parse, and execute the JavaScript.
Also, no hydration step, making your app load and become interactive faster.
Direct access to server-side resources
Direct access to server-side resources
Server components introduce a new type of React component specifically meant for
server-side operation only.
Direct access to server-side resources
Server components introduce a new type of React component specifically meant for
server-side operation only.
Server Components can directly access database and file systems, making data fetching super efficient without any client-side processing.
Enhanced Security
Enhanced Security
Server Components run on the server, and all the sensitive data like API keys or any other private keys are very much secured.
Improved Data Fetching
Improved Data Fetching
Server Components allow us to fetch data on the server.
Improved Data Fetching
Server Components allow us to fetch data on the server.
With this application performance will improve and rendering time will also be reduced.
Caching
Caching
We can catch the result on the server and we can reuse them for different users and requests.
Faster initial page load and First Contentful Paint
Faster initial page load and First Contentful Paint
Users can see HTML content immediately as HTML is generated on the server. No need to wait for JavaScript download and execute.
SEO Improved
SEO Improved
Now Search Engin can easily index your server-render HTML.
Efficient streaming
Efficient streaming
Server Components can divide the rendering process into chunks and stream them to the client as they become available.
Efficient streaming
Server Components can divide the rendering process into chunks and stream them to the client as they become available.
This allows users to view HTML content sooner, rather than waiting for the server to render the entire page.
Efficient streaming
Server Components can divide the rendering process into chunks and stream them to the client as they become available.
This allows users to view HTML content sooner, rather than waiting for the server to render the entire page.
Server Components manage data fetching and static rendering, while Client Components are responsible for rendering interactive elements.
When referring to React Server Components (RSC), we are addressing three main elements.
When referring to React Server Components (RSC), we are addressing three main elements.
Your Browser
When referring to React Server Components (RSC), we are addressing three main elements.
Your Browser
Next.js (framework)
When referring to React Server Components (RSC), we are addressing three main elements.
Your Browser
Next.js (framework)
React (Library)
Client
Client
Client Request
Client
Client Request
Match
Request URL
Client
Client Request
Match
Request URL
Render Server Component
Client
Client Request
Match
Request URL
Render Server Component
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
Client
Client Request
Match
Request URL
Render Server Component
RSC Payload
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
Client
Client Request
Match
Request URL
Render Server Component
RSC Payload
Generate HTML on the Server
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
Client
Client Request
Match
Request URL
Render Server Component
RSC Payload
Generate HTML on the Server
Stream HTML
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
Client
Client Request
Match
Request URL
Render Server Component
RSC Payload
Generate HTML on the Server
Stream HTML
Non-Interactive UI
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
Client
Client Request
Match
Request URL
Render Server Component
RSC Payload
Generate HTML on the Server
Stream HTML
Non-Interactive UI
Same time it also Send RSC Payload
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
Client
Client Request
Match
Request URL
Render Server Component
RSC Payload
Generate HTML on the Server
Stream HTML
Non-Interactive UI
Same time it also Send RSC Payload
Progrssively Render UI
Final UI
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
Client
Client Request
Match
Request URL
Render Server Component
RSC Payload
Generate HTML on the Server
Stream HTML
Non-Interactive UI
Same time it also Send RSC Payload
Progrssively Render UI
Hydration
Final UI
Interactive UI
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
Client
Client
Client Request
Client
Client Request
Match
Request URL
Client
Client Request
Match
Request URL
Render Server Component
Client
Client Request
Match
Request URL
Render Server Component
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
Client
Client Request
Match
Request URL
Render Server Component
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
RSC Payload
Client
Client Request
Match
Request URL
Render Server Component
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
RSC Payload
RSC Payload
Client
Client Request
Match
Request URL
Render Server Component
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
RSC Payload
Route Render
RSC Payload
Client
Client Request
Match
Request URL
Render Server Component
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
RSC Payload
Route Render
RSC Payload
Reconciliation
Client
Client Request
Match
Request URL
Render Server Component
Render Server Component and any Child component that are also server component, converting them in a special format known as RSC payload
RSC Payload
Route Render
RSC Payload
Reconciliation
Update Ui
Static Rendering
Dynamic Rendering
Streaming
Static rendering is a server rendering strategy in which an HTML page is generated when we build our application.
Static rendering is a server rendering strategy in which an HTML page is generated when we build our application.
You can think your page will generated in advanced before user requests.
Static rendering is a server rendering strategy in which an HTML page is generated when we build our application.
You can think your page will generated in advanced before user requests.
Once we build, those pages can be cached by CDNs and served to the users instantly.
Static rendering is a server rendering strategy in which an HTML page is generated when we build our application.
You can think your page will generated in advanced before user requests.
Once we build, those pages can be cached by CDNs and served to the users instantly.
With this approach, whenever any user request the page, same page will be shared
to the different users.
Static rendering we can use for blog posts, product list pages, documentation etc...
We do not have to do anything for this, Static Rendering is default strategy in the app route.
We do not have to do anything for this, Static Rendering is default strategy in the app route.
During the build process, all routes are prepared automatically and we do not have
to do any additional steps.
We do not have to do anything for this, Static Rendering is default strategy in the app route.
During the build process, all routes are prepared automatically and we do not have
to do any additional steps.
Wait a second—you keep mentioning generating HTML during the build process, but we haven’t actually built the application yet, right? We’re still in development mode.
In production, we create an optimized build, deploy it, and cannot make changes once development is complete.
In production, we create an optimized build, deploy it, and cannot make changes once development is complete.
A development server, however, is designed with the developer's experience in mind.
In production, we create an optimized build, deploy it, and cannot make changes once development is complete.
A development server, however, is designed with the developer's experience in mind.
In production, pages are pre-rendered once during the build phase.
In production, we create an optimized build, deploy it, and cannot make changes once development is complete.
A development server, however, is designed with the developer's experience in mind.
In production, pages are pre-rendered once during the build phase.
In development environment, pages pre-rendering for each request.
Dynamic rendering is a server rendering strategy where routes are rendered when
user requests the route.
Dynamic rendering is a server rendering strategy where routes are rendered when
user requests the route.
This is helpful when you need to display personalized data or information that is only accessible at the time of the request. think like cookies or URL parameters.
Dynamic rendering is a server rendering strategy where routes are rendered when
user requests the route.
This is helpful when you need to display personalized data or information that is only accessible at the time of the request. think like cookies or URL parameters.
Examples of where dynamic rendering is useful include news websites, customized shopping pages, and social media feeds.
If a "dynamic function" or "dynamic API" is detected, Next.js automatically shifts to dynamic rendering for the full route.
If a "dynamic function" or "dynamic API" is detected, Next.js automatically shifts to dynamic rendering for the full route.
Next.js dynamic functions are:
cookie()
header()
connection()
draftMode()
searchParams props
after()
If you use any of them full route automatically sifts to dynamic rendering at request time.
generateStaticParams is a function that operates
Alongside dynamic route segments
Create static routes at the time of the build.
Insted of on demand at the request time
This provides us with a significant performance improvement.
generateStaticParams is a function that operates
Think we have a product catalogue with categories and products
/products/[category]/[product]/page.tsx
Manage the behaviour when a dynamic segment is accessed that wasn’t pre-generated using generateStaticParams()
Manage the behaviour when a dynamic segment is accessed that wasn’t pre-generated using generateStaticParams()
True - Next.js will statically render the page on demand for any dynamic segments not included in generateStaticParams()
Manage the behaviour when a dynamic segment is accessed that wasn’t pre-generated using generateStaticParams()
True - Next.js will statically render the page on demand for any dynamic segments not included in generateStaticParams()
False - Next.js will return a 404 error for any dynamic segments not included in our
pre-rendered list
Streaming is a technique that enables the server to render the UI progressively.
Streaming is a technique that enables the server to render the UI progressively.
Tasks are divided into smaller chunks and streamed to the client as soon as they are ready.
Streaming is a technique that enables the server to render the UI progressively.
Tasks are divided into smaller chunks and streamed to the client as soon as they are ready.
As a result, users can start seeing parts of the page instantly, without waiting for the full page to finish loading
Streaming is a technique that enables the server to render the UI progressively.
Tasks are divided into smaller chunks and streamed to the client as soon as they are ready.
As a result, users can start seeing parts of the page instantly, without waiting for the full page to finish loading
The App Router in Next.js comes with built-in support for streaming.
Server Components
Server Components
Data fetching
Server Components
Data fetching
Directly access backend resources
Server Components
Data fetching
Directly access backend resources
Keeping sensitive information (like access tokens and API keys) secure on the server
Server Components
Data fetching
Directly access backend resources
Keeping sensitive information (like access tokens and API keys) secure on the server
handling large dependencies server side - which means less JavaScript will
download by the users.
Client Components
Client Components
For handling interactivity
Client Components
For handling interactivity
Add event listeners (like onClick(), onChange(), etc..)
Client Components
For handling interactivity
Add event listeners (like onClick(), onChange(), etc..)
Managing state (using hooks like useState or useEffect)
Client Components
For handling interactivity
Add event listeners (like onClick(), onChange(), etc..)
Managing state (using hooks like useState or useEffect)
Working with browser APIs
Client Components
For handling interactivity
Add event listeners (like onClick(), onChange(), etc..)
Managing state (using hooks like useState or useEffect)
Working with browser APIs
Work with custom hooks
In Next.js, a context provider is used similarly to React, wrapping parts of your application to share global data (e.g., themes, user authentication) across components. It is typically placed in root layout.tsx to ensure the context is available throughout the entire app.
In Next.js, a context provider is used similarly to React, wrapping parts of your application to share global data (e.g., themes, user authentication) across components. It is typically placed in root layout.tsx to ensure the context is available throughout the entire app.
In Server Components React Context isn't supported.
In Next.js, a context provider is used similarly to React, wrapping parts of your application to share global data (e.g., themes, user authentication) across components. It is typically placed in root layout.tsx to ensure the context is available throughout the entire app.
In Server Components React Context isn't supported.
If you try to set up a context at the top level of your app, you’ll encounter an error.
In Next.js, a context provider is used similarly to React, wrapping parts of your application to share global data (e.g., themes, user authentication) across components. It is typically placed in root layout.tsx to ensure the context is available throughout the entire app.
In Server Components React Context isn't supported.
If you try to set up a context at the top level of your app, you’ll encounter an error.
To resolve this, create your context and render its provider within a separate
client component.
As a result, you can fetch data wherever you need it in your components without worrying about duplicate network requests.
As a result, you can fetch data wherever you need it in your components without worrying about duplicate network requests.
React will execute the fetch operation just once and utilize the same result for any additional calls within the same render cycle
As a result, you can fetch data wherever you need it in your components without worrying about duplicate network requests.
React will execute the fetch operation just once and utilize the same result for any additional calls within the same render cycle
It’s a feature of React, and as a result, it’s also available in Next.js
There are two main data fetching patterns you should consider when fetching data
inside components.
There are two main data fetching patterns you should consider when fetching data
inside components.
Sequential
Parallel
There are two main data fetching patterns you should consider when fetching data
inside components.
Sequential
Parallel
Requests within a component tree rely on one another, which can result in
increased loading times.
There are two main data fetching patterns you should consider when fetching data
inside components.
Parallel
Requests in a route are started simultaneously, allowing data to load in parallel and reducing the overall loading time.
We'll be using two handy tools—SQLite and Prisma.
We'll be using two handy tools—SQLite and Prisma.
SQLite
We'll be using two handy tools—SQLite and Prisma.
SQLite
A simple database that operates on a file-based system to store project-related information
We'll be using two handy tools—SQLite and Prisma.
SQLite
A simple database that operates on a file-based system to store project-related information
It operates without a server or complex configuration, making it ideal for
learning and prototyping.
We'll be using two handy tools—SQLite and Prisma.
SQLite
A simple database that operates on a file-based system to store project-related information
It operates without a server or complex configuration, making it ideal for
learning and prototyping.
Prisma
We'll be using two handy tools—SQLite and Prisma.
SQLite
A simple database that operates on a file-based system to store project-related information
It operates without a server or complex configuration, making it ideal for
learning and prototyping.
Prisma
A tool that simplifies communication with your database.
We'll be using two handy tools—SQLite and Prisma.
SQLite
A simple database that operates on a file-based system to store project-related information
It operates without a server or complex configuration, making it ideal for
learning and prototyping.
Prisma
A tool that simplifies communication with your database.
It's like a mediator, helping your code communicate effectively with SQLite.
Server actions are async functions that run exclusively on the server.
Server actions are async functions that run exclusively on the server.
They can be invoked in both Server and Client Components to process form submissions and perform data mutations in Next.js applications.
Server actions are async functions that run exclusively on the server.
They can be invoked in both Server and Client Components to process form submissions and perform data mutations in Next.js applications.
You should use Server Actions when you
Server actions are async functions that run exclusively on the server.
They can be invoked in both Server and Client Components to process form submissions and perform data mutations in Next.js applications.
need to execute database operations securely on the server
You should use Server Actions when you
Server actions are async functions that run exclusively on the server.
They can be invoked in both Server and Client Components to process form submissions and perform data mutations in Next.js applications.
need to execute database operations securely on the server
You should use Server Actions when you
want to reduce API boilerplate code
Server actions are async functions that run exclusively on the server.
They can be invoked in both Server and Client Components to process form submissions and perform data mutations in Next.js applications.
need to execute database operations securely on the server
You should use Server Actions when you
want to reduce API boilerplate code
need progressive enhancement for forms
Server actions are async functions that run exclusively on the server.
They can be invoked in both Server and Client Components to process form submissions and perform data mutations in Next.js applications.
need to execute database operations securely on the server
You should use Server Actions when you
want to reduce API boilerplate code
need progressive enhancement for forms
want to optimize for performance
A Server Action can be declared using the React "use server" directive.
A Server Action can be declared using the React "use server" directive.
You can place the directive
A Server Action can be declared using the React "use server" directive.
You can place the directive
At the top of an async function marks the function as a Server Action.
A Server Action can be declared using the React "use server" directive.
You can place the directive
At the top of an async function marks the function as a Server Action.
At the top of a file makes all exported functions in that file Server Actions.
useFormStatus is a React hook that provides details about the last form submission.
useFormStatus is a React hook that provides details about the last form submission.
const status = useFormStatus()
useFormStatus is a React hook that provides details about the last form submission.
const status = useFormStatus()
pending: A true or false value that tells if the parent <form> is submitting
useFormStatus is a React hook that provides details about the last form submission.
const status = useFormStatus()
pending: A true or false value that tells if the parent <form> is submitting
data: It contains the form's submission details in an object format.
useFormStatus is a React hook that provides details about the last form submission.
const status = useFormStatus()
pending: A true or false value that tells if the parent <form> is submitting
data: It contains the form's submission details in an object format.
method: A string value ("get" or "post") that indicates the HTTP method used for the
form submission.
useFormStatus is a React hook that provides details about the last form submission.
const status = useFormStatus()
pending: A true or false value that tells if the parent <form> is submitting
data: It contains the form's submission details in an object format.
method: A string value ("get" or "post") that indicates the HTTP method used for the
form submission.
action: A reference to the function that was provided to the parent <form> as its action prop.
useFormStatus is a React hook that provides details about the last form submission.
const status = useFormStatus()
pending: A true or false value that tells if the parent <form> is submitting
data: It contains the form's submission details in an object format.
method: A string value ("get" or "post") that indicates the HTTP method used for the
form submission.
action: A reference to the function that was provided to the parent <form> as its action prop.
We'll use "pending" to disable the submit button while the form is submitting
Both can check if a form is submitted and disable the submit button, but they have an important difference.
Both can check if a form is submitted and disable the submit button, but they have an important difference.
The pending state from useFormStatus is only meant for tracking form submissions.
Both can check if a form is submitted and disable the submit button, but they have an important difference.
The pending state from useFormStatus is only meant for tracking form submissions.
The isPending state from useActionState can be used with any action, not just form submissions
Both can check if a form is submitted and disable the submit button, but they have an important difference.
The pending state from useFormStatus is only meant for tracking form submissions.
The isPending state from useActionState can be used with any action, not just form submissions
Use the pending state from useFormStatus when creating reusable components that will be inside forms, like submit buttons or loading spinners for different forms in your app.
Both can check if a form is submitted and disable the submit button, but they have an important difference.
The pending state from useFormStatus is only meant for tracking form submissions.
The isPending state from useActionState can be used with any action, not just form submissions
Use the pending state from useFormStatus when creating reusable components that will be inside forms, like submit buttons or loading spinners for different forms in your app.
Use isPending from useActionState when tracking server actions that don’t have to be tied to form submissions, giving you more flexibility.