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.
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