How to add Tag Input in Next.js ?
Last Updated :
25 Jul, 2024
In this article, we are going to learn how we can add Tag input 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.
Approach: To add our tag input, we are going to use the react-tag-input-component package. The react-tag-input-component package helps us to integrate the tag input in our app. So first, we will install the react-tag-input-component package and then we will add a tag input on our homepage.
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 react-tag-input-component package using the below command:
npm i react-tag-input-component
Project Structure: It will look like this.

Adding the Tag Input: After installing the package, we can easily add a tag input on any page in our app. For this example, we are going to add a tag input to our homepage.
Add the below content in the index.js file:
JavaScript
import React, { useState } from "react";
import { TagsInput } from "react-tag-input-component";
export default function TagInput(){
const [selected, setSelected] = useState(["gfg"]);
return (
<div>
<h1>NextJs Tag Input - GeeksforGeeks</h1>
<div>
<h1>Add Tags</h1>
<pre>{JSON.stringify(selected)}</pre>
<TagsInput
value={selected}
onChange={setSelected}
name="tags"
placeHolder="tags"
/>
<em>Enter tags</em>
</div>
</div>
);
};
Explanation: In the above example first, we are importing the TagsInput component and useState hook from react. Then we are using the useState hook to store the value of the tag. After that, we are adding our tags input using the installed package.
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 Phone Input in Next.js ? In this article, we are going to learn how we can add phone input 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 add our phone input we are going to use the react-phone-input-2 packa
2 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 Tweets in Next.js ? 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.ApproachTo
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 Video Player in Next.js ? Adding a video player in a Next.js application enhances the user experience by enabling video playback. The react-player library simplifies integrating various video sources such as YouTube, Vimeo, and local files. In this article, we are going to learn how we can add Video Player in NextJS. Approac
2 min read