Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Next.js Tutorial
  • Next.js Components
  • Next.js Functions
  • Next.js Deployment
  • Next.js Projects
  • Next.js Routing
  • Next.js Styles
  • Next.js Server-Side Rendering
  • Next.js Environment Variables
  • Next.js Middleware
  • Next.js Typescript
  • Next.js Image Optimization
  • Next.js Data Fetching
Open In App
Next Article:
What is SSR in NextJS ?
Next article icon

What is SSR in NextJS ?

Last Updated : 12 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Server-Side Rendering (SSR) in Next.js generates HTML on the server for each request, enhancing SEO and initial load times by delivering fully rendered content before it reaches the client.

What is SSR?

SSR or Server Side Rendering is also known as dynamic rendering. In SSR the page is generated each time the server gets a request. Pages on which the data have to change for a particular type of request, those pages use SSR as data is not the same for every request and may vary with it. To use SSR for a page, we need to export an async function called "getServerSideProps". This async function is called each time a request is made for the page.

Syntax:

export default function Page({ data }) {
return <>YOU CAN DISPLAY YOUR DATA ACCORDINGLY</>;
}
export async function getServerSideProps() {
// Your code
const data = [];

// Passing data to the Page using props
return {
props: { data },
};
}

Note: In place of data you can take any other name of the variable. Also, you can pass multiple props by separating them with commas ",". 

Below is the Step by Step Implementation

Step 1: Create NextJS Application: You can create a new NextJs project using the below command:

npx create-next-app gfg

Project Structure:

So, right now we have a Next Js application named my-awesome-app whose directory structure is shown in the image below:

Directory structure

Step 2: So, let us create a page with endpoint as "/users" by creating a "users.js" in our "pages" folder and then fetching the users from a dummy API and then showing that data in that endpoint.

Dummy api used:

https://jsonplaceholder.typicode.com/users

Create a users.js file. 

 

created "users.js" file

Step 3: Add the following code to the "pages/users.js" file:

JavaScript
// Inside "pages/users.js"  export default function Users( {data} ){     return (         <div>             <h1>List of Users</h1>             <ul>                 {data.map((user,index)=>{                  return <li key={index}>Id : {user.id} ,                       Name : {user.name} , Email : {user.email}                  </li>                    })}             </ul>         </div>     ) }  export async function getServerSideProps() {          // Fetching data     const res = await fetch(     'https://jsonplaceholder.typicode.com/users');     const data = await res.json() ;      // Passing data to the Product Page using props     return {         props : {data}     } } 

Step to run the application: Using either of the given 2 commands start the dev server:

npm run dev

Or

yarn run dev

Output: And now go to the "http://localhost:3000/users" to get the output.

Output of the above code

Next Article
What is SSR in NextJS ?

M

mycodenotein
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • ReactJS
  • Geeks Premier League
  • Geeks-Premier-League-2022
  • Next.js

Similar Reads

    What's new in Next.js 13
    Next.js 13 brings a host of innovative features and improvements, elevating the framework's capabilities and enhancing the development experience. From a cutting-edge build tool to advanced routing and server-side rendering features, Next.js 13 is designed to streamline workflows and boost performan
    5 min read
    SEO in Next JS
    Search Engine Optimization (SEO) is crucial for enhancing the visibility and ranking of your website in search engine results. Next.js provides robust features and tools that make optimizing your site for SEO easier and more effective.In this article, we'll explore how to use Next.js for SEO to opti
    5 min read
    Getting Started with Next JS
    NextJS is an open-source React framework for building full-stack web applications ( created and maintained by Vercel ). You can use React Components to build user interfaces, and NextJS for additional features and optimizations. It is built on top of Server Components, which allows you to render ser
    9 min read
    Why Next.js is Popular?
    Next.js is a robust React framework designed to enhance web development with capabilities like server-side rendering (SSR), static site generation (SSG), and incremental static regeneration (ISR). Its comprehensive feature set simplifies the development process, improves performance, and boosts SEO,
    4 min read
    Next.js Functions: userAgent
    Detecting the userAgent is now very important in SSR applications using Next.js, which provides a userAgent string. Doing so can be quite helpful to optimize the rendering, find some errors that are browser-specific, or change the client experience based on the device it is accessed from. Next.js is
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences