For class component

In app.js

import React from "react";
import Modal from "./Component/Modal";
import "./styles.css";
class App extends React.Component {
  state = {
    show: false
  };
  showModal = e => {
    this.setState({
      show: !this.state.show
    });
  };
  render() {
    return (
      <div className="App">
        <button
          class="toggle-button"
          id="centered-toggle-button"
          onClick={e => {
            this.showModal(e);
          }}
        >
          {" "}
          show Modal{" "}
        </button>

        <Modal onClose={this.showModal} show={this.state.show}>
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis
          deserunt corrupti, ut fugit magni qui quasi nisi amet repellendus non
         
        </Modal>
      </div>
    );
  }
}

export default App;

In component/modal

Make file named index.js

import React from "react";
import "./modal.css";
import PropTypes from "prop-types";

export default class Modal extends React.Component {
  onClose = e => {
    this.props.onClose && this.props.onClose(e);
  };
  render() {
    if (!this.props.show) {
      return null;
    }
    return (
      <div class="modal" id="modal">
        <h2>Modal Window</h2>
        <div class="content">{this.props.children}</div>
        <div class="actions">
          <button class="toggle-button" onClick={this.onClose}>
            close
          </button>
        </div>
      </div>
    );
  }
}
Modal.propTypes = {
  onClose: PropTypes.func.isRequired,
  show: PropTypes.bool.isRequired
};

Make file modal.css

html,
body {
  height: 100%;
}
body {
  background: #eee;
  display: flex;
  justify-content: center;
  align-items: center;
}
.modal {
  width: 500px;
  background: white;
  border: 1px solid #ccc;
  transition: 1.1s ease-out;
  box-shadow: -2rem 2rem 2rem rgba(0, 0, 0, 0.2);
  filter: blur(0);
  transform: scale(1);
  opacity: 1;
  visibility: visible;
}
.modal.off {
  opacity: 0;
  visibility: hidden;
  filter: blur(8px);
  transform: scale(0.33);
  box-shadow: 1rem 0 0 rgba(0, 0, 0, 0.2);
}
@supports (offset-rotation: 0deg) {
  offset-rotation: 0deg;
  offset-path: path("M 250,100 S -300,500 -700,-200");
  .modal.off {
    offset-distance: 100%;
  }
}
@media (prefers-reduced-motion) {
  .modal {
    offset-path: none;
  }
}
.modal h2 {
  border-bottom: 1px solid #ccc;
  padding: 1rem;
  margin: 0;
}
.modal .content {
  padding: 1rem;
}
.modal .actions {
  border-top: 1px solid #ccc;
  background: #eee;
  padding: 0.5rem 1rem;
}
.modal .actions button {
  border: 0;
  background: #78f89f;
  border-radius: 5px;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  line-height: 1;
}
#centered-toggle-button {
  position: absolute;
}

This is an example of modal with class component. Please check if this helps you.

@Python

Second example

You can try this, if that does not work. This is bit easy also.

Using react bootstrap module. In App.js

import React from 'react';  
import './App.css';  
import { Button,Modal} from 'react-bootstrap';  
class App extends React.Component {  
  constructor(){  
    super();  
    this.state={  
      show:false  
    }  
  }  
  handleModal(){  
    this.setState({show:!this.state.show})  
  }  
  render(){  
    return (  
      <div>  
        <h2 align='center'>Example of Modal in Reactjs</h2>  
        <div className="modalClass">  
          <Button onClick={()=>this.handleModal()}>Click To Open Modal</Button>  
        </div>  
          
        <Modal show={this.state.show} onHide={()=>this.handleModal()}>  
          <Modal.Header closeButton>This is a Modal Heading</Modal.Header>  
          <Modal.Body>This is a Modal Body</Modal.Body>  
          <Modal.Footer>  
            <Button onClick={()=>this.handleModal()}>Close</Button>  
            <Button onClick={()=>this.handleModal()}>Save</Button>  
          </Modal.Footer>  
        </Modal>  
      </div>  
    )  
  }  
}  
export default App; 

In css file just add

.modalClass {  
  text-align: center;  
  margin-top: 100px;  
} 
Answer from user18246964 on Stack Overflow
🌐
npm
npmjs.com › package › reactjs-popup
reactjs-popup - npm
September 6, 2023 - import React from 'react'; import Popup from 'reactjs-popup'; import 'reactjs-popup/dist/index.css'; export default () => ( <Popup trigger={<button> Trigger</button>} position="right center"> <div>Popup content here !!</div> </Popup> ); ... ...
      » npm install reactjs-popup
    
Published   Sep 06, 2023
Version   2.0.6
Author   Youssouf EL AZIZI
🌐
PopupSmart
popupsmart.com › popupsmart conversion rate optimization & digital marketing blog › how to create a react popup & customize it in 4 steps
How to Create a React Popup & Customize it in 4 Steps
2 weeks ago - A React popup is a dynamic overlay that displays content on top of a page without navigating away, keeping users in context while collecting input or surfacing information. Whether you're creating a modal, an alert box, or a custom form popup, this guide walks through the full process: how to build one in four steps, how to make it accessible, and which libraries to consider depending on your project's needs.
Discussions

How to add a simple popup in REACT? - javascript
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I am building an app using React. I am new to it. So here I want to make a popup that will pop when a button is clicked. It is basically a login/signup system. More on stackoverflow.com
🌐 stackoverflow.com
What is best way to create popup modal in react js
Save yourself the headache, https://headlessui.com/react/dialog More on reddit.com
🌐 r/reactjs
22
44
March 12, 2023
Creating a popup in ReactJs
I am new in ReactJs and trying to create a popup window through onclick event. I am following this resource - https://dev.to/skptricks/create-simple-popup-example-in-react-application-5g7f File -... More on stackoverflow.com
🌐 stackoverflow.com
June 5, 2023
How do I create a popup window in react.js when the button and function are in separate file?
Problem Description: There is a button on a webpage, and when I click the button, there will be a popup containing an image. The button is in the file called "index.jsx", and clicking on the button... More on stackoverflow.com
🌐 stackoverflow.com
November 1, 2020
People also ask

Can I create a React popup with TypeScript?
Yes, and TypeScript adds significant value for popup components. Define interfaces for your popup's props; open state, close handler, children, and any content-specific props, to catch type mismatches at compile time rather than runtime. Most major popup libraries, including reactjs-popup, MUI, and Headless UI, ship with TypeScript definitions. The TypeScript React handbook covers component typing patterns in depth.
🌐
popupsmart.com
popupsmart.com › popupsmart conversion rate optimization & digital marketing blog › how to create a react popup & customize it in 4 steps
How to Create a React Popup & Customize it in 4 Steps
What's the difference between a popup and a modal in React?
A popup is a lightweight overlay for quick information or contextual alerts, often positioned near a trigger element (like a tooltip or notification). A modal is a specific type of popup that takes over the full screen with an overlay backdrop, demands user attention, and requires explicit dismissal. Modals always need focus trapping; simple popups may not. Use modals for critical decisions or forms, and lighter popups for supplementary information. The modal design best practices guide on UX Planet covers the decision criteria in detail.
🌐
popupsmart.com
popupsmart.com › popupsmart conversion rate optimization & digital marketing blog › how to create a react popup & customize it in 4 steps
How to Create a React Popup & Customize it in 4 Steps
What's the right way to handle popup state in a large React application?
In large apps, managing popup visibility as local component state doesn't scale. When multiple components need to trigger the same popup, or when popup content depends on global data (auth state, user profile, cart contents), lift the popup state to a Context provider or your existing state management solution. Create a single PopupManager context that tracks which popup is active, what data to display, and handles open/close transitions globally. This prevents duplicate popup instances, makes testing easier, and gives you a single place to add analytics tracking for popup interactions.
🌐
popupsmart.com
popupsmart.com › popupsmart conversion rate optimization & digital marketing blog › how to create a react popup & customize it in 4 steps
How to Create a React Popup & Customize it in 4 Steps
🌐
Mobiscroll
demo.mobiscroll.com › react › popup
React Popup Examples | Mobiscroll
4 weeks ago - Pop-over examples with customizable content, button configuration and behavior. For React JS. Last update: Mar 17, 2026
🌐
Dead Simple Chat
deadsimplechat.com › blog › creating-a-reusable-pop-up-modal-in-react-from-scratch
Creating A Reusable Pop- Up Modal in React from Scratch
November 29, 2023 - First create a new file in the src folder and name it Modal.js then · import React from 'react'; function Modal({ children, onClose }) { return ( <div style={styles.overlay}> <div style={styles.modal}> {children} <button style={styles.closeButton} ...
Top answer
1 of 2
3

For class component

In app.js

import React from "react";
import Modal from "./Component/Modal";
import "./styles.css";
class App extends React.Component {
  state = {
    show: false
  };
  showModal = e => {
    this.setState({
      show: !this.state.show
    });
  };
  render() {
    return (
      <div className="App">
        <button
          class="toggle-button"
          id="centered-toggle-button"
          onClick={e => {
            this.showModal(e);
          }}
        >
          {" "}
          show Modal{" "}
        </button>

        <Modal onClose={this.showModal} show={this.state.show}>
          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis
          deserunt corrupti, ut fugit magni qui quasi nisi amet repellendus non
         
        </Modal>
      </div>
    );
  }
}

export default App;

In component/modal

Make file named index.js

import React from "react";
import "./modal.css";
import PropTypes from "prop-types";

export default class Modal extends React.Component {
  onClose = e => {
    this.props.onClose && this.props.onClose(e);
  };
  render() {
    if (!this.props.show) {
      return null;
    }
    return (
      <div class="modal" id="modal">
        <h2>Modal Window</h2>
        <div class="content">{this.props.children}</div>
        <div class="actions">
          <button class="toggle-button" onClick={this.onClose}>
            close
          </button>
        </div>
      </div>
    );
  }
}
Modal.propTypes = {
  onClose: PropTypes.func.isRequired,
  show: PropTypes.bool.isRequired
};

Make file modal.css

html,
body {
  height: 100%;
}
body {
  background: #eee;
  display: flex;
  justify-content: center;
  align-items: center;
}
.modal {
  width: 500px;
  background: white;
  border: 1px solid #ccc;
  transition: 1.1s ease-out;
  box-shadow: -2rem 2rem 2rem rgba(0, 0, 0, 0.2);
  filter: blur(0);
  transform: scale(1);
  opacity: 1;
  visibility: visible;
}
.modal.off {
  opacity: 0;
  visibility: hidden;
  filter: blur(8px);
  transform: scale(0.33);
  box-shadow: 1rem 0 0 rgba(0, 0, 0, 0.2);
}
@supports (offset-rotation: 0deg) {
  offset-rotation: 0deg;
  offset-path: path("M 250,100 S -300,500 -700,-200");
  .modal.off {
    offset-distance: 100%;
  }
}
@media (prefers-reduced-motion) {
  .modal {
    offset-path: none;
  }
}
.modal h2 {
  border-bottom: 1px solid #ccc;
  padding: 1rem;
  margin: 0;
}
.modal .content {
  padding: 1rem;
}
.modal .actions {
  border-top: 1px solid #ccc;
  background: #eee;
  padding: 0.5rem 1rem;
}
.modal .actions button {
  border: 0;
  background: #78f89f;
  border-radius: 5px;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  line-height: 1;
}
#centered-toggle-button {
  position: absolute;
}

This is an example of modal with class component. Please check if this helps you.

@Python

Second example

You can try this, if that does not work. This is bit easy also.

Using react bootstrap module. In App.js

import React from 'react';  
import './App.css';  
import { Button,Modal} from 'react-bootstrap';  
class App extends React.Component {  
  constructor(){  
    super();  
    this.state={  
      show:false  
    }  
  }  
  handleModal(){  
    this.setState({show:!this.state.show})  
  }  
  render(){  
    return (  
      <div>  
        <h2 align='center'>Example of Modal in Reactjs</h2>  
        <div className="modalClass">  
          <Button onClick={()=>this.handleModal()}>Click To Open Modal</Button>  
        </div>  
          
        <Modal show={this.state.show} onHide={()=>this.handleModal()}>  
          <Modal.Header closeButton>This is a Modal Heading</Modal.Header>  
          <Modal.Body>This is a Modal Body</Modal.Body>  
          <Modal.Footer>  
            <Button onClick={()=>this.handleModal()}>Close</Button>  
            <Button onClick={()=>this.handleModal()}>Save</Button>  
          </Modal.Footer>  
        </Modal>  
      </div>  
    )  
  }  
}  
export default App; 

In css file just add

.modalClass {  
  text-align: center;  
  margin-top: 100px;  
} 
2 of 2
1

The first step is to import packages.

import React from "react";
import { Modal, Button, Form } from "react-bootstrap";
import "bootstrap/dist/css/bootstrap.css";

Then in App function you can set state to show and hide the modal popup.

function App() {
  const [show, setShow] = useState(false);

  const handleShow = () => setShow(true);

  return (
    <>
      <div
        className="d-flex align-items-center justify-content-center"
        style={{ height: "100vh" }}
      >
        <Button variant="primary" onClick={handleShow}>
          Launch Form modal
        </Button>
      </div>
      <Modal show={show}>
        <Modal.Header closeButton>
          <Modal.Title>Login Form</Modal.Title>
        </Modal.Header>
        <Modal.Body>
          <></>
        </Modal.Body>
        <Modal.Footer>
          <Button variant="secondary">Close Modal</Button>
        </Modal.Footer>
      </Modal>
    </>
  );
}

This is just an example, hope this helps you.

🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › how-to-create-popup-box-in-reactjs
How to create Popup box in React JS ? - GeeksforGeeks
Then import the popup component of the library and enclose the popup content inside with the Popup Components along with the required props. Step 1: Create a React application using the following command:
Published   July 23, 2025
Find elsewhere
🌐
Medium
medium.com › @danielbillson › creating-a-popup-in-react-with-hooks-and-context-4806bc7d82e7
Creating a popup in React with Hooks and Context | by Daniel Billson | Medium
April 6, 2020 - This can be achieved with both the useEffect hook and a setTimeout. Making use of the usePopup hook we created earlier we can grab the value and the clearPopup function. The value will be used in the dependency array of the useEffect to make ...
🌐
DEV Community
dev.to › chukwuma1976 › its-popping-pop-ups-made-simple-in-react-5cd8
It's Popping: Pop Ups Made Simple In React - DEV Community
February 18, 2023 - import React from 'react'; function PopUp({showPopUp, closePopUp, children}){ if (!showPopUp) {return null} return ( <div className="PopUp" > <button onClick={closePopUp}>close</button> {children} </div> ); }; export default PopUp; Here is the ...
🌐
MUI
v6.mui.com › base-ui › react-popup
React Popup component - MUI Base
See how it's done in the Disable portal section below. The following demo shows how to create and style a basic Popup. Click Toggle Popup to see how it behaves: ... import * as React from 'react'; import { Unstable_Popup as BasePopup } from '@mui/base/Unstable_Popup'; import { styled } from '@mui/system'; export default function SimplePopup() { const [anchor, setAnchor] = React.useState<null | HTMLElement>(null); const handleClick = (event: React.MouseEvent<HTMLElement>) => { setAnchor(anchor ?
🌐
CodePen
codepen.io › bastianalbers › pen › PWBYvz
Simple react popup example
May 4, 2023 - h1 { margin: 0; padding: 0; } html, body, .app { margin: 0; padding: 0; position: relative; width: 100%; height: 100vh; } .popup { position: fixed; width: 100%; height: 100%; top: 0; left: 0; right: 0; bottom: 0; margin: auto; background-color: rgba(0,0,0, 0.5); } .popup_inner { position: absolute; left: 25%; right: 25%; top: 25%; bottom: 25%; margin: auto; background: white; } ... class Popup extends React.Component { render() { return ( <div className='popup'> <div className='popup_inner'> <h1>{this.props.text}</h1> <button onClick={this.props.closePopup}>close me</button> </div> </div> ); }
🌐
Medium
medium.com › @daniela.sandoval › creating-a-popup-window-using-js-and-react-4c4bd125da57
Creating A PopUp Window Using JS And React | by Daniela Sandoval | Medium
July 23, 2025 - A small guide on creating the infamous “popup” window that is both a blessing and a curse for users with the help of JS and React.
🌐
DEV Community
dev.to › g10dra › create-custom-popup-component-in-react-1o18
Create Custom PopUp Component in React - DEV Community
July 21, 2021 - This will be a fully Reusable Component that we can Invoke from any of the component entire our project. Step 1: Create a file named custom-popup.module.css with following code :
🌐
MakeUseOf
makeuseof.com › home › programming › add pop-up effects to your react.js app
Add Pop-Up Effects to Your React.js App
October 22, 2022 - After that, you can add a pop-up using either of two methods. You can use React hooks or an external module. The hooks approach is simpler and only requires a few lines of code. First, you need to create a function that will open the pop-up.
🌐
DEV Community
dev.to › skptricks › create-simple-popup-example-in-react-application-5g7f
Create Simple Popup Example In React Application - DEV Community
January 4, 2024 - So in this example we have created component named as " Popup" and that helps to display the popup message, whenever user clicks on " Click To Launch Popup" button. ... Popup.js This is a popup component that helps to display popup message to user. import React from 'react'; import './style.css'; class Popup extends React.Component { render() { return ( <div className='popup'> <div className='popup\_inner'> <h1>{this.props.text}</h1> <button onClick={this.props.closePopup}>close me</button> </div> </div> ); } } export default Popup;
🌐
Minutemailer
minutemailer.github.io › react-popup
React popup example
July 21, 2021 - You should only mount it once, ... to avoid positioning problems. import React from 'react'; import ReactDom from 'react-dom'; import Popup from 'react-popup'; ReactDom.render( <Popup />, document.getElementById('popupContainer') );...
🌐
DhiWise
dhiwise.com › post › guide-to-creating-engaging-user-experiences-with-react-popups
Effective Ways To Use React Popups For Enhanced User Interfaces
January 13, 2025 - Creating a React popup component is a way to know the modals in React. Learn how to create a simple react popup component to control the visibility.
🌐
DEV Community
dev.to › afromatt6288 › create-a-popup-form-for-login-and-then-style-it-37jl
React: Create a Popup Form for Login and then Style it - DEV Community
August 11, 2022 - In this blog post, we've shown you how to create a popup form for login and user creation using React.