Add Comment Section in Next.js
Last Updated :
29 Jul, 2024
In this article, we are going to learn how we can add a Comment Section in NextJs. Using the comment section users can write their thoughts and queries in your NextJs app.
NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditionally.
Approach: To add our Comment section we are going to use the Disqus platform. Disqus is a networked community platform used by hundreds of thousands of sites all over the web. So first, we will create an account in the Disqus platform and install the Disqus package and then we will create a new file in which we will write code for our comment section. Then on our homepage, we will import our comment section.
Create NextJS Application: You can create a new NextJs project using the below command:
npx create-next-app gfg
Install the required package: Now we will install the Disqus package using the below command:
npm install disqus-react
Project Structure: It will look like this.

Create Account in Disqus: Next we have to create a new account in Disqus. So to do this follow the below steps:
1. Go to Disqus’s Official Site and Click on Get Started. Then click on Sign Up.

2. After Signing up, Click on the ‘I want to install Disqus on my site’ Button.

3. After that, Enter your website name and choose a category.

That’s it. Now we are ready to add the Comment section in our NextJs app.
Adding Comment Section: Now to add our comment section we are going to create a new folder in our gfg directory with the name ‘components’ and inside this folder, we will create a new javascript file with the name ‘Comment.js‘.
Add the below content in our Comment.js file:
JavaScript
import {DiscussionEmbed} from "disqus-react"
const Comments = () => {
const disqusShortname = "Demo-GfG"
const disqusConfig = {
url: "http://localhost:3000",
identifier:'123',
title: "Demo Post"
}
return (
<div>
<DiscussionEmbed
shortname={disqusShortname}
config={disqusConfig}
/>
</div>
)
}
export default Comments;
In the above code, we are first importing DiscussionEmbed from our disqus-react. After that, we are creating a new component with the name Comments and inside this component, we are storing the disqusShortname. Website URL, identifier, and title in different constant variables. Then we are returning our DiscussionEmbed function.
Now we can import the above file to our homepage to display our comment section.
Add the below content in the index.js file:
JavaScript
import React from 'react'
import Comments from '../components/Comment'
export default function Text() {
return (
<div>
<h1>Comments - GeeksforGeeks</h1>
<Comments/>
</div>
)
}
Now when we run our NextJs app the index.js file will act as the homepage of the app.
Steps to run the application: Run the below command in the terminal to run the app.
npm run dev
Output:
Similar Reads
How to add ESLint in Next.js ?
ESLint is a popular linting tool for identifying and fixing issues in JavaScript code. Adding ESLint to your Next.js project ensures that your code follows best practices and maintains a consistent style. This enhances code quality, helps catch errors early, and makes the codebase easier to maintain
3 min read
How to add Slider in Next.js ?
Adding a slider in Next.js involves integrating a slider component, like react-range, managing its state using React hooks and applying styles for customization, enhancing user interaction and input precision in your application. ApproachTo add our Slider we are going to use the react-range package.
2 min read
How to add Calendar in Next.js ?
Adding a calendar to a Next.js application enhances scheduling and event management. We can just install and use the available npm package. In this article, we are going to learn how we can add a calendar loader in NextJS. ApproachTo add our calendar we are going to use the react-calendar package. T
2 min read
How to add Timer in Next.js ?
In this article, we are going to learn how we can add Timer in NextJS. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditionally.
2 min read
How to add CodeBlock in Next.js ?
In this article, we are going to learn how we can add CodeBlock in NextJS. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditiona
2 min read
How to add Web Share in Next.js ?
The Web Share API enables web applications to share content (like URLs, text, or files) to other apps installed on a user's device, such as social media platforms, messaging apps, or email clients. Integrating the Web Share API into a Next.js project enhances user experience by providing a seamless
2 min read
How to add Testimonials in Next.js ?
In this article, we are going to learn how we can add the Testimonials in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components con
2 min read
Server Components in Next.js
Server Components in Next.js offer a way to build components that are rendered on the server rather than on the client. This feature enhances performance by reducing the amount of JavaScript sent to the browser and allows for faster initial page loads. In this post, we will explore the Server Compon
4 min read
How to add Draggable Components in Next.js ?
In this article, we are going to learn how we can add Draggable Components in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components
2 min read
How to add Image Carousel in Next.js ?
In this article, we are going to learn how we can add an Image Carousel in NextJS. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. ApproachTo create image carousel in next.js we are going to use a react-r
2 min read