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
🌐
Mobiscroll
demo.mobiscroll.com › react › popup
React Popup Examples | Mobiscroll
This allows you to have the popup bottom-positioned on mobile devices, centered on tablets, and anchored to input on larger screens to enhance the user experience. Change the viewport · 375px 576px 768px 992px 1200px · Change demo · Event creation modal Get started with this example · View code on GitHub · View React JS code on GitHub View React TS code on GitHub ·
🌐
npm
npmjs.com › package › reactjs-popup
reactjs-popup - npm
... To start using reactjs popup ...ist/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
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
🌐
Minutemailer
minutemailer.github.io › react-popup
React popup example
Pro tip: If you dispatch multiple popups they will be queued and displayed one at the time as the popups closes. The prompt helper has been removed in v0.7.0. To help you out a bit, here's an example of how you can do it yourself, the recommended way. More about plugins further down. /** The prompt content component */ class Prompt extends React.Component { constructor(props) { super(props); this.state = { value: this.props.defaultValue }; this.onChange = (e) => this._onChange(e); } componentDidUpdate(prevProps, prevState) { if (prevState.value !== this.state.value) { this.props.onChange(this.
🌐
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
January 18, 2024 - 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. A React popup is an interactive overlay element built with React that renders content above the existing page without full navigation.
🌐
CodeSandbox
codesandbox.io › examples › package › reactjs-popup
reactjs-popup examples - CodeSandbox
Use this online reactjs-popup playground to view and fork reactjs-popup example apps and templates on CodeSandbox.
🌐
Elazizi
react-popup.elazizi.com
React Popup | ReactJs Popup: Modals, Tooltips and Menus, All in One
This is a simple demo to demonstrate how you can create Modals, Tooltips, Menus using reactjs-popup.
🌐
MUI
v6.mui.com › base-ui › react-popup
React Popup component - MUI Base
Note that it may cause visual clipping if a Popup is placed in a container without visible overflow. You can use fixed positioning to prevent clipping when not using portals. The Popup has the strategy prop which is responsible for determining how the position is calculated. When set to "fixed", the fixed CSS position will be used and the Popup won't be subject to overflow hiding. ... <PopupWithTrigger id="popup-with-portal" buttonLabel="With a portal" /> <PopupWithTrigger id="popup-without-portal" buttonLabel="No portal, default strategy" disablePortal /> <PopupWithTrigger id="popup-without-portal-fixed" buttonLabel="No portal, 'fixed' strategy" disablePortal strategy="fixed" />
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › how-to-create-popup-box-in-reactjs
How to create Popup box in React JS ? - GeeksforGeeks
// Filename - App.js import React ... ... Example 2: This example uses the reactjs-popup library to create a popup modal that appears at the click of a button and closes in the same behavior....
Published   July 23, 2025
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.

🌐
DevExtreme
js.devexpress.com › React › Demos › WidgetsGallery › Demo › Popup › Overview
React Popup - Overview | React Example
import React, { useCallback, useMemo, useState } from 'react'; import { Popup, Position, ToolbarItem } from 'devextreme-react/popup'; import notify from 'devextreme/ui/notify'; import { EmployeeItem } from './EmployeeItem.js'; import { employees } from './data.js'; export default function App() { const [currentEmployee, setCurrentEmployee] = useState(null); const [popupVisible, setPopupVisible] = useState(false); const [positionOf, setPositionOf] = useState(''); const showInfo = useCallback((employee) => { setCurrentEmployee(employee); setPositionOf(`#image${employee.ID}`); setPopupVisible(tru
🌐
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 - I called this pop up component ... 'react'; function PopUp({showPopUp, closePopUp, children}){ if (!showPopUp) {return null} return ( <div className="PopUp" > <button onClick={closePopUp}>close</button> {children} </div> ); }; export default PopUp;...
🌐
Scaler
scaler.com › home › topics › react › react popup box
React Popup Box - Scaler Topics
May 4, 2023 - Here is an example of how to create a basic popup box: ... This will create a button that, when clicked, will trigger the popup box to appear with the content "Popup content here" inside it. Please note that you need to have already installed react and react-dom to install reactjs-popup. We're going to use the reactjs-popup package to build our Popup in React Js ...
🌐
CodePen
codepen.io › bastianalbers › pen › PWBYvz
Simple react popup example
h1 { margin: 0; padding: 0; } html, ... { return ( <div className='popup'> <div className='popup_inner'> <h1>{this.props.text}</h1> <button onClick={this.props.closePopup}>close me</button> </div> </div> ); }...
🌐
Clue Mediator
cluemediator.com › create-simple-popup-in-reactjs
Create simple Popup in ReactJS - Clue Mediator
Create Simple Popup Example In React Application, Create modal popup in React JS.
🌐
DhiWise
dhiwise.com › post › guide-to-creating-engaging-user-experiences-with-react-popups
Effective Ways To Use React Popups For Enhanced User Interfaces
January 4, 2024 - Creating a simple React popup component is a great way to get familiar with the concept of modals in React. A modal is a type of popup that typically overlays the page's main content, focusing the user's attention on a specific task or message. Here's a basic example of how to create a simple react popup component using functional components and the useState hook :
🌐
Medium
medium.com › @byron.skoutaris › simple-popup-example-in-react-281a949bc3df
Simple Popup Example In React
October 14, 2022 - This is our main app where we will ... "./components/Popup/Popup";const App = () => { const [open, setOpen] = useState(false); return ( <div> <button onClick={() => setOpen(true)}> Click to Open Popup</button> {open ?...
🌐
DevExtreme
js.devexpress.com › React › Documentation › Guide › UI_Components › Popup › Getting_Started_with_Popup
React Popup - Getting Started | React Documentation v25.1
App.js · import React from 'react'; ... 'devextreme-react/popup'; const App = () => { return ( <div className="App"> <Popup id="popup"> {/* Configuration goes here */} </Popup> </div> ); } export default App; NOTE · The component may ...
🌐
React.js Examples
reactjsexample.com › tag › popup
Popup - React.js Examples
May 20, 2018 - Its simple event system allows you to place the modal in the 27 July 2017 ... Simple modal component for React. 27 July 2017 ... react-dock Resizable dockable react component. Live Demo http://alexkuz.github.io/react-dock/demo/ GitHub 26 July 2017 ... Accessible modal dialog component for React. 16 July 2017 ... React Native Popup Dialog A React Native Popup Dialog Easy Use & Support Custom Animation.
🌐
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 - In the above example the p tag will be where the {children} is · <button style={styles.closeButton} onClick={onClose}>X</button> We have the onClick event on the close button so that when the button is clicked the onClick function will be called · Next, we have the styles button that has the styles defined inside it. and lastly we are exporting the Modal component so that we can import in the App.js · In the app.js we are importing React and useState from react and we are also importing out Modal component from the modal.js file