How to Add Tweets in Next.js ?
Last Updated :
31 Jul, 2024
Adding tweets in Next.js involves using Twitter's embed feature or API to display tweets. You can embed tweets directly in components or fetch and display them using server-side rendering or client-side data fetching. In this article, we are going to learn how we can add Tweets in NextJs.
Approach
To add our tweets we are going to use the react-tweet-embed package. The react-tweet-embed package helps us to add tweets anywhere in our app. So first, we will install the react-tweet-embed package and then we will add a tweet on our homepage. It takes the tweet id to access and display the tweet on the page.
Steps to Create Next.js Project
Step 1: You can create a new NextJS project using the below command:
npx create-next-app gfg
Step 2: Switch to the Project directory
cd gfg
Step 3: Now we will install the react-tweet-embed package using the below command:
npm i react-tweet-embed
Project Structure:

The updated dependencies in the package.json file are:
"dependencies": {
"next": "14.2.4",
"react": "^18",
"react-dom": "^18",
"react-tweet-embed": "^2.0.0"
}
Example: This example demonstrates addingtweets in the next app using the react-tweet-embed package which accepts the tweed id and display the tweet to the page.
JavaScript
// Filename - pages/index.js
import TweetEmbed from "react-tweet-embed";
import React from "react";
export default function Tweets() {
return (
<div>
<h3>
GeeksforGeeks - Tweet
</h3>
<TweetEmbed
id="1456503289512710147"
options={{ theme: "dark" }}
/>
</div>
);
}
Explanation: In the above example first, we are importing the TweetEmbed component from the installed package. After that, we are adding the id and options parameter in our TweetEmbed component. You can find the tweet id in the tweet link.
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 TypeScript in Next.js ? In this article, we will learn how to add TypeScript in Next.js.Why should we use TypeScript in our project? The fundamental concept of TypeScript is that it is type-strict, which means that each entity, be it a variable, a function, or an object has a definite data type. It allows minimum bugs in t
5 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 Stylesheet in Next.js ? In Next.js, adding a stylesheet enhances your app's styling capabilities. Import CSS files directly in your components or pages using ES6 import syntax. Next.js optimizes and includes these styles in the build process, ensuring efficient and modular CSS management.In this post, we are going to learn
4 min read
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 Typewriter effect in Next.js ? In this article, we are going to learn how we can add the Typewriter effect 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 component
2 min read