How to Open Popup Window in ReactJS

In this blog, we learn about How to Open Popup Window in ReactJS.
Important Point:
Strongly request first install node.js and visual studio code link for download visual studio code editor in your machine.Node.Js download from give link
download node.js
Then follow my step.
Step 1.First Install global package open command prompt and write this command and hit enter.

npm install -g create-react-app

Step 2.After installation of npm .Now we can create React Application.Write this command for creating App

create-react-app myapp //myapp is the application name

Step 3.After completion download go to the folder and start npm

cd myapp
//then  start npm 
npm start //automatically open in browser

Step 4.Now open your application visual studio code editor. click on file->” Open Folder”->Go to your project and select application myapp then click ok.
Step 5. Open src folder you can see some auto-generated file in src folder.Some file in src folder we don’t need first delete this file like “App.css”,”App.test.js” and “App.js”.
After that open index.js file from src folder then delete auto generated code from index.js file. copy this code on your index.js page.

////this package is used for create new component
import React from 'react';
////this package is used for insert in DOM
import ReactDOM from 'react-dom';
import './index.css';  //import index.css page

class TodoListCourse extends React.Component{

            <div className='popup'>
          <div className='popup_style'>
                    return<ToDoCourse key={courses} courses={courses}
             <button onClick={this.props.closePopup}>Cancel</button>

class ToDoCourse extends React.Component{

class App extends React.Component {
    constructor() {
      this.state = {
        showPopup: false
//tooglePopup is a method name
    togglePopup() {
//Set the state
        showPopup: !this.state.showPopup
    render() {
       return (
        <div className='app'>
          <button onClick={this.togglePopup.bind(this)}>show popup</button>
        {this.state.showPopup ? 
              text='User List' 
            : null
//you can find root element index.html page


Step 6.Open the index.css page and copy this code on your index.css.

body {
  margin: 0;
  padding: 0;
  font-family: sans-serif;


.popup {
  position: fixed;
  width: 110%;
  height: 110%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
.popup_style {
  position: absolute;
  left: 30%;
  right: 30%;
  top: 30%;
  bottom: 30%;
  margin: auto;
  background: powderblue;

  background-color: aqua;

Finally Screenshot describe output after run the aaplication.Click on Show Popup button then you can see reasult.

If This article helped you. Humble request to you please donate small amount only 5 Ruppes or 1 Ruppes so that I can help the needy poor people. Send amount this phonepe upi id : 8800846247@ybl or google pay 8800846247. Thank you from my bottom of heart.

Any question and suggestion related to this topic please comment.Thank you


Leave a Reply

Your email address will not be published. Required fields are marked *