Monday, November 18, 2024
Google search engine
HomeLanguagesHow to add Popup in NextJS ?

How to add Popup in NextJS ?

In this article, we are going to learn how we can add Popup 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 Popup in NextJs we are going to use the reactjs-popup package. The reactjs-popup package helps us to integrate different types of popups. So first, we will install the reactjs-popup package and then we will add popups 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 reactjs-popup package using the below command:

npm i reactjs-popup

Project Structure: It will look like this.

Adding Popup: In this example, we are going to add the popup on the homepage of our app using the package that we installed. For this, add the below content in the index.js file.

index.js




import React from 'react';
import Popup from 'reactjs-popup';
import 'reactjs-popup/dist/index.css';
  
export default function PopupGfg(){
  return(
  <div>
    <h4>NextJs Popup - neveropen</h4>
    <Popup trigger={<button> Click to open popup </button>} 
     position="right center">
      <div>neveropen</div>
      <button>Click here</button>
    </Popup>
  </div>
  )
};


Explanation: In the above example first, we are importing the Popup component from the react-popup package. After that, we are using our Popup component to add a popup with a button to trigger the popup.

Steps to run the application: Run the below command in the terminal to run the app.

npm run dev

Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments