Here is modern way to achieve this using React Hooks

import React, { useState } from "react";

const PopUp = ({ idMessage }) => {
  // create state `open` with default as false
  const [open, setOpen] = useState(false);
  return (
    <>
      {/* click of button toggles `open` value therefore visibility */}
      <button
        onClick={() => setOpen(!open)}
        type="button"
        className="btn btn-primary"
        data-toggle="modal"
        data-target={`#${idMessage}`}
      >
        {idMessage}
      </button>
      {/* If open is true show your <div /> */}
      {open && (
        <div
          className="modal fade"
          id={idMessage}
          tabIndex="-1"
          role="dialog"
          aria-labelledby="exampleModalLabel"
          aria-hidden="true"
        >
          content
        </div>
      )}
    </>
  );
};

export default PopUp;
Answer from vitjbr on Stack Overflow
🌐
Medium
enetoolveda.medium.com › open-a-popup-window-react-db81c8c180e5
Open a PopUp Window, React. Today I will try to show you how to… | by Ernesto Jara Olveda | Medium
February 10, 2020 - We need three more components so let’s create them. touch ./src/{window-opener.js,Son.js,Home.js} This Component will be the Parent Component, the main “window”. As you can tell is the App.js that comes with create-react-app I just did some changes. All this component will do is print on screen whatever we write on the child window input. This is the popup or the “son” xD.
🌐
npm
npmjs.com › package › react-popout
react-popout - npm
React popout is a React component wrapping window.open allowing you to host content in a browser popup window.
      » npm install react-popout
    
Published   Dec 31, 2024
Version   4.0.0
Author   Jake Ginnivan
Discussions

javascript - Open a popUp in react
I want to open a popup when I click a button on react, I have this but the popUp wont appear: More on stackoverflow.com
🌐 stackoverflow.com
open a pop up window in reactjs application - Stack Overflow
I want pass properties to the child element which will open in popup and then capture the action taken in the child element to parent element. Can someone tell me how best we can do this. ... They called Modal. You can check the react-modal library. More on stackoverflow.com
🌐 stackoverflow.com
April 2, 2018
reactjs - How can I handle an event to open a window in react js? - Stack Overflow
I want to open a window after clicking the fshare: My render() return is like this More on stackoverflow.com
🌐 stackoverflow.com
React Button Click to open Popup - javascript
I don't have much experience with React. What I want to do is to be able to open a popup when I press the button. I've looked through a lot of examples but couldn't figure out why it wasn't. Here i... More on stackoverflow.com
🌐 stackoverflow.com
July 2, 2022
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 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
How do I test React popups effectively?
Use Jest and React Testing Library for unit tests, verify the popup opens on trigger click, closes on the close button, and closes on Escape. Add ARIA attribute assertions to catch accessibility regressions. Use Cypress or Playwright for end-to-end keyboard navigation tests. Key edge cases: rapid open/close cycles and correct focus restoration after close. The React Testing Library docs cover accessible selector strategies.
🌐
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
🌐
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 - Trigger Events: Popups activate on specific user actions: button clicks, mouse hovers, scroll depth, or time on page. Using React hooks for event handling ensures smooth responses without performance issues. State Management: React's useState hook manages visibility. The open boolean drives conditional rendering to show or hide the popup based on user interactions.
🌐
npm
npmjs.com › package › react-new-window
react-new-window - npm
November 27, 2022 - import React from 'react' import NewWindow from 'react-new-window' const Demo = () => ( <NewWindow> <h1>Hi 👋</h1> </NewWindow> ) When <NewWindow /> is mounted a popup window will be opened.
      » npm install react-new-window
    
Published   Nov 27, 2022
Version   1.0.1
Author   Rubens Mariuzzo
Top answer
1 of 3
5

Here is modern way to achieve this using React Hooks

import React, { useState } from "react";

const PopUp = ({ idMessage }) => {
  // create state `open` with default as false
  const [open, setOpen] = useState(false);
  return (
    <>
      {/* click of button toggles `open` value therefore visibility */}
      <button
        onClick={() => setOpen(!open)}
        type="button"
        className="btn btn-primary"
        data-toggle="modal"
        data-target={`#${idMessage}`}
      >
        {idMessage}
      </button>
      {/* If open is true show your <div /> */}
      {open && (
        <div
          className="modal fade"
          id={idMessage}
          tabIndex="-1"
          role="dialog"
          aria-labelledby="exampleModalLabel"
          aria-hidden="true"
        >
          content
        </div>
      )}
    </>
  );
};

export default PopUp;
2 of 3
3

You could consider creating the popup as a re-usable component, that just renders the props.message. Suppose you have the button in App.js, here is how you can add the click listener on it.

class App extends Component {
  state = {showPopup: false};

  openPopupHandler = () => {
    this.setState({showPopup: true});
  }
  
  closePopupHandler = () => {
    this.setState({showPopup: false});
  }

  
  render() {
    let popup = null;
    if(this.state.showPopup) {
      popup = (<Popup message='the text you need to display' closeMe={this.closePopupHandler}/>);
    } 
    return(
      <div>
      <button onClick={this.clicked}>Click me </button>
      {popup}
      </div>
    );
  }
}

And you can define the popup component as given below.

Popup.js

const popup = (props) => {
return (
  <div>
    <p>{props.message}</p>
    <button onClick={props.closeMe}>Close Popup</button>
  </div>
);
}

Also, style the popup component with the size as per your requirement and with an z-index greater than that of the parent component.

🌐
DEV Community
dev.to › taronvardanyan › how-to-open-and-communicate-with-a-popup-window-in-react-with-typescript-f98
🪟 How to Open and Communicate with a Popup Window in React (with TypeScript) - DEV Community
June 26, 2025 - // PopupPage.tsx import { useEffect, useState } from 'react'; const PopupPage = () => { const [message, setMessage] = useState<any>(null); useEffect(() => { const handleMessage = (event: MessageEvent) => { // Optionally: restrict to same-origin in production if (event.origin !== window.location.origin) return; console.log('Received message:', event.data); setMessage(event.data); }; window.addEventListener('message', handleMessage); return () => window.removeEventListener('message', handleMessage); }, []); return ( <div style={{ padding: 20 }}> <h2>Popup Window</h2> <p> <strong>Message from par
Find elsewhere
🌐
GitHub
github.com › JakeGinnivan › react-popout
GitHub - JakeGinnivan/react-popout: React popout is a React component wrapping window.open allowing you to host content in a browser popup window.
React popout is a React component wrapping window.open allowing you to host content in a browser popup window. - JakeGinnivan/react-popout
Starred by 192 users
Forked by 56 users
Languages   TypeScript 93.6% | JavaScript 6.4% | TypeScript 93.6% | JavaScript 6.4%
🌐
GitHub
github.com › rmariuzzo › react-new-window
GitHub - rmariuzzo/react-new-window: 🔲 Pop new windows in React, using `window.open`.
import React from 'react' import NewWindow from 'react-new-window' const Demo = () => ( <NewWindow> <h1>Hi 👋</h1> </NewWindow> ) When <NewWindow /> is mounted a popup window will be opened.
Starred by 464 users
Forked by 108 users
Languages   JavaScript 98.4% | HTML 1.6%
Top answer
1 of 2
6

They called Modal.

You can check the react-modal library.

Here is a simple example of react-modal being used in an app with some custom styles and focusable input elements within the modal content:

import React from 'react';
import ReactDOM from 'react-dom';
import Modal from 'react-modal';

const customStyles = {
  content : {
    top                   : '50%',
    left                  : '50%',
    right                 : 'auto',
    bottom                : 'auto',
    marginRight           : '-50%',
    transform             : 'translate(-50%, -50%)'
  }
};

// Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/)
Modal.setAppElement('#yourAppElement')

class App extends React.Component {
  constructor() {
    super();

    this.state = {
      modalIsOpen: false
    };

    this.openModal = this.openModal.bind(this);
    this.afterOpenModal = this.afterOpenModal.bind(this);
    this.closeModal = this.closeModal.bind(this);
  }

  openModal() {
    this.setState({modalIsOpen: true});
  }

  afterOpenModal() {
    // references are now sync'd and can be accessed.
    this.subtitle.style.color = '#f00';
  }

  closeModal() {
    this.setState({modalIsOpen: false});
  }

  render() {
    return (
      <div>
        <button onClick={this.openModal}>Open Modal</button>
        <Modal
          isOpen={this.state.modalIsOpen}
          onAfterOpen={this.afterOpenModal}
          onRequestClose={this.closeModal}
          style={customStyles}
          contentLabel="Example Modal"
        >

          <h2 ref={subtitle => this.subtitle = subtitle}>Hello</h2>
          <button onClick={this.closeModal}>close</button>
          <div>I am a modal</div>
          <form>
            <input />
            <button>tab navigation</button>
            <button>stays</button>
            <button>inside</button>
            <button>the modal</button>
          </form>
        </Modal>
      </div>
    );
  }
}

ReactDOM.render(<App />, appElement);

You can see more examples here

2 of 2
3

The popup is called a modal. There are multiple libraries that support modals. React bootstrap provides a neat modal. Or if you want to use modal alone there are libraries such as react-modal and react-responsive-modal

🌐
GitHub
github.com › RyanNerd › react-new-improved-window
GitHub - RyanNerd/react-new-improved-window: React New and Improved Window popup using the window.open API
import React from 'react' import NewImprovedWindow from 'react-new-improved-window' const Demo = () => ( <Index> <h1>Hi 👋</h1> </Index> ) When <Index /> is mounted a popup window will be opened.
Starred by 15 users
Forked by 2 users
Languages   TypeScript 50.3% | JavaScript 41.3% | HTML 6.9% | CSS 1.5% | TypeScript 50.3% | JavaScript 41.3% | HTML 6.9% | CSS 1.5%
🌐
npm
npmjs.com › package › reactjs-popup
reactjs-popup - npm
September 6, 2023 - Reactjs-popup is a simple react popup component that helps you create simple and complex Modals, tooltips, and Menus for your next React App.
      » npm install reactjs-popup
    
Published   Sep 06, 2023
Version   2.0.6
Author   Youssouf EL AZIZI
🌐
Scott Logic
blog.scottlogic.com › 2019 › 10 › 29 › popout-windows-in-react.html
Popout Windows in React
October 29, 2019 - import React from 'react'; import ReactDOM from 'react-dom'; interface Props { title: string; // The title of the popout window closeWindow: () => void; // Callback to close the popout } interface State { externalWindow: Window | null; // The popout window containerElement: HTMLElement | null; // The root element of the popout window } export default class Popout extends React.Component<Props, State> { constructor(props: Props) { super(props); this.state = { externalWindow: null, containerElement: null }; } // When we create this component, open a new window public componentDidMount() { const
🌐
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 22, 2019 - 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.
🌐
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 - The useEffect hook could add custom animations when the modal is opened or closed. Floating window popups are a unique UI component that appears over the main content and can be moved and resized by the user, similar to traditional desktop application windows. To create a floating window in React, ...
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › how-to-create-popup-box-in-reactjs
How to create Popup box in React JS ? - GeeksforGeeks
We will use the Reactjs-popup library to Create Popup Box in React JS.
Published   July 23, 2025
🌐
CodePen
codepen.io › bastianalbers › pen › PWBYvz
Simple react popup example
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> ); } } class App extends React.Component { constructor() { super(); this.state = { showPopup: false }; } togglePopup() { this.setState({ showPopup: !this.state.showPopup }); } render() { return ( <div className='app'> <h1>hihi</h1> <button onClick={this.togglePopup.bind(this)}>show popup</button> <button onClick={() => {alert('woooooooot?');}}>try me when popup is open</button> <p>Ganz