SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Downloaden Sie, um offline zu lesen
JogjaJS / 28 October 2023
React Server
Components
in Next.js
• Senior Software Engineer / Tech
Lead Frontend @
• Currently helping Jakpat
migrating internal dashboard
from (Laravel + AngularJS) to
(React + Next.js)
Hanief Utama
Once upon a time…
• HTML ( 30 years ago )
• PHP ( 28 years ago )
• Javascript ( 27 years ago )
• CSS ( 26 years ago )
• React ( 10 years ago )
First Web Server By Coolcaesar at the English-language Wikipedia, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=395096
Client
Server
0 10 20 30
Chart adapted from Josh W Comeau [https://www.joshwcomeau.com/react/server-components/]
Client Side
Rendering
Download
Javascript
Render Shell Render Content
Database
Query
First Paint
Content
Painted
Page Interactive
The OG React way
Server Side
Rendering
Client
Server
0 10 20 30
Chart adapted from Josh W Comeau [https://www.joshwcomeau.com/react/server-components/]
Download
Javascript
Render
Shell
Render Content
Database
Query
Hydrate
First
Paint
Page
Interactive
Content
Painted
Same as CSR but better SEO
Why not this?
Client
Server
0 10 20 30
Chart adapted from Josh W Comeau [https://www.joshwcomeau.com/react/server-components/]
Download
Javascript
Render
App
Database
Query
Hydrate
First Paint
Content Painted Page Interactive
Some frameworks already have
this
React Server Components
Server Component Client Component
Server Component Client Component
Render only on server Render on server and client
New kind of component The component that we already know
Default component ‘use client’;
No state Can use state
Can import Client Component Can ONLY import Client Component
App
Header Article
HitCounter Discussion
Comment Comment
App
Header
‘Use client’;
Article
HitCounter Discussion
Comment Comment
App
Header
‘Use client’;
Article
HitCounter Discussion
Comment Comment
Client Boundary
Chart adapted from Josh W Comeau [https://www.joshwcomeau.com/react/server-components/]
Next.js is the only
framework that o
ff
er full
support of RSC
Using Server Components in Next.js
• Next.js 13.4+
• Use App Router
• Server Components is default
Pros?
• Smaller bundle size
• Faster rendering
• Server is controllable vs di
ff
erent
kind of browser
• Hydrate only what is needed
• Keep sensitive data on the server
• Caching
Cons?
• No CSS-in-JS
• React Context doesn’t work
• More things to think about
• More work on server
• Need to control which part hydrate
Should I use React Server Components?
• Yes, if you are already deeply invested in React + Next.js
• Yes, if you have control of the server
• Yes, if performance is very important to you
• Yes, if your bundle size is too big
• No, if your life is complex enough already
Adoption strategy
• Add the “use client” directive to the root of your app
• Move the directive as low in the rendering tree as you can
• Adopt advanced patterns when performance issues arise
Thank you

Weitere ähnliche Inhalte

Ähnlich wie React Server Component in Next.js by Hanief Utama

Performance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsPerformance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsDenis Izmaylov
 
The Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJSThe Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJSWeblineIndia
 
Vitali zaidman Do You Need Server Side Rendering? What Are The Alternatives?
Vitali zaidman Do You Need Server Side Rendering? What Are The Alternatives?Vitali zaidman Do You Need Server Side Rendering? What Are The Alternatives?
Vitali zaidman Do You Need Server Side Rendering? What Are The Alternatives?CodeValue
 
Building a website without a webserver on Azure
Building a website without a webserver on AzureBuilding a website without a webserver on Azure
Building a website without a webserver on AzureTodd Whitehead
 
Why ReactJS Is The Right Choice For Your Next Web Application
Why ReactJS Is The Right Choice For Your Next Web ApplicationWhy ReactJS Is The Right Choice For Your Next Web Application
Why ReactJS Is The Right Choice For Your Next Web ApplicationThinkTanker Technosoft PVT LTD
 
Hire React Remix Top Developers
Hire React Remix Top DevelopersHire React Remix Top Developers
Hire React Remix Top DevelopersBluebash LLC
 
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...Asish Padhy
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison500Tech
 
Headless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricksHeadless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricksArtsem Prashkovich
 
Front End Development
Front End DevelopmentFront End Development
Front End DevelopmentEahaRani
 
What are the business benefits of ReactJS for web and mobile applications_.pdf
What are the business benefits of ReactJS for web and mobile applications_.pdfWhat are the business benefits of ReactJS for web and mobile applications_.pdf
What are the business benefits of ReactJS for web and mobile applications_.pdfReactJS
 
React.js for Rails Developers
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails DevelopersArkency
 
Bootstrap vs React Which is the best front-end framework.pdf
Bootstrap vs React Which is the best front-end framework.pdfBootstrap vs React Which is the best front-end framework.pdf
Bootstrap vs React Which is the best front-end framework.pdfLaura Miller
 

Ähnlich wie React Server Component in Next.js by Hanief Utama (20)

React.js at Cortex
React.js at CortexReact.js at Cortex
React.js at Cortex
 
Performance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsPerformance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React Applications
 
Universal React apps in Next.js
Universal React apps in Next.jsUniversal React apps in Next.js
Universal React apps in Next.js
 
The Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJSThe Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJS
 
React loadable
React loadableReact loadable
React loadable
 
Vitali zaidman Do You Need Server Side Rendering? What Are The Alternatives?
Vitali zaidman Do You Need Server Side Rendering? What Are The Alternatives?Vitali zaidman Do You Need Server Side Rendering? What Are The Alternatives?
Vitali zaidman Do You Need Server Side Rendering? What Are The Alternatives?
 
Building a website without a webserver on Azure
Building a website without a webserver on AzureBuilding a website without a webserver on Azure
Building a website without a webserver on Azure
 
Why ReactJS Is The Right Choice For Your Next Web Application
Why ReactJS Is The Right Choice For Your Next Web ApplicationWhy ReactJS Is The Right Choice For Your Next Web Application
Why ReactJS Is The Right Choice For Your Next Web Application
 
Hire React Remix Top Developers
Hire React Remix Top DevelopersHire React Remix Top Developers
Hire React Remix Top Developers
 
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...
Building Responsive Intranet using Sharepoint Framework solutions - Asish Pad...
 
Sug bangalore - headless jss
Sug bangalore - headless jssSug bangalore - headless jss
Sug bangalore - headless jss
 
Next.js - ReactPlayIO.pptx
Next.js - ReactPlayIO.pptxNext.js - ReactPlayIO.pptx
Next.js - ReactPlayIO.pptx
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison
 
Building SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.jsBuilding SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.js
 
From MVC to React
From MVC to ReactFrom MVC to React
From MVC to React
 
Headless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricksHeadless CMS. Sitecore JSS getting started, tips and tricks
Headless CMS. Sitecore JSS getting started, tips and tricks
 
Front End Development
Front End DevelopmentFront End Development
Front End Development
 
What are the business benefits of ReactJS for web and mobile applications_.pdf
What are the business benefits of ReactJS for web and mobile applications_.pdfWhat are the business benefits of ReactJS for web and mobile applications_.pdf
What are the business benefits of ReactJS for web and mobile applications_.pdf
 
React.js for Rails Developers
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails Developers
 
Bootstrap vs React Which is the best front-end framework.pdf
Bootstrap vs React Which is the best front-end framework.pdfBootstrap vs React Which is the best front-end framework.pdf
Bootstrap vs React Which is the best front-end framework.pdf
 

Kürzlich hochgeladen

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Kürzlich hochgeladen (20)

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 

React Server Component in Next.js by Hanief Utama

  • 1. JogjaJS / 28 October 2023 React Server Components in Next.js
  • 2. • Senior Software Engineer / Tech Lead Frontend @ • Currently helping Jakpat migrating internal dashboard from (Laravel + AngularJS) to (React + Next.js) Hanief Utama
  • 3. Once upon a time… • HTML ( 30 years ago ) • PHP ( 28 years ago ) • Javascript ( 27 years ago ) • CSS ( 26 years ago ) • React ( 10 years ago ) First Web Server By Coolcaesar at the English-language Wikipedia, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=395096
  • 4.
  • 5. Client Server 0 10 20 30 Chart adapted from Josh W Comeau [https://www.joshwcomeau.com/react/server-components/] Client Side Rendering Download Javascript Render Shell Render Content Database Query First Paint Content Painted Page Interactive The OG React way
  • 6. Server Side Rendering Client Server 0 10 20 30 Chart adapted from Josh W Comeau [https://www.joshwcomeau.com/react/server-components/] Download Javascript Render Shell Render Content Database Query Hydrate First Paint Page Interactive Content Painted Same as CSR but better SEO
  • 7. Why not this? Client Server 0 10 20 30 Chart adapted from Josh W Comeau [https://www.joshwcomeau.com/react/server-components/] Download Javascript Render App Database Query Hydrate First Paint Content Painted Page Interactive Some frameworks already have this
  • 10. Server Component Client Component Render only on server Render on server and client New kind of component The component that we already know Default component ‘use client’; No state Can use state Can import Client Component Can ONLY import Client Component
  • 13. App Header ‘Use client’; Article HitCounter Discussion Comment Comment Client Boundary Chart adapted from Josh W Comeau [https://www.joshwcomeau.com/react/server-components/]
  • 14.
  • 15. Next.js is the only framework that o ff er full support of RSC
  • 16. Using Server Components in Next.js • Next.js 13.4+ • Use App Router • Server Components is default
  • 17. Pros? • Smaller bundle size • Faster rendering • Server is controllable vs di ff erent kind of browser • Hydrate only what is needed • Keep sensitive data on the server • Caching Cons? • No CSS-in-JS • React Context doesn’t work • More things to think about • More work on server • Need to control which part hydrate
  • 18. Should I use React Server Components? • Yes, if you are already deeply invested in React + Next.js • Yes, if you have control of the server • Yes, if performance is very important to you • Yes, if your bundle size is too big • No, if your life is complex enough already
  • 19. Adoption strategy • Add the “use client” directive to the root of your app • Move the directive as low in the rendering tree as you can • Adopt advanced patterns when performance issues arise