I was recently looking for a nice solution to this without adding React-Bootstrap to my project (as Bootstrap 4 is about to be released).

This is my solution: https://jsfiddle.net/16j1se1q/1/

let Modal = React.createClass({
    componentDidMount(){
        $(this.getDOMNode()).modal('show');
        $(this.getDOMNode()).on('hidden.bs.modal', this.props.handleHideModal);
    },
    render(){
        return (
          <div className="modal fade">
            <div className="modal-dialog">
              <div className="modal-content">
                <div className="modal-header">
                  <button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                  <h4 className="modal-title">Modal title</h4>
                </div>
                <div className="modal-body">
                  <p>One fine body&hellip;</p>
                </div>
                <div className="modal-footer">
                  <button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
                  <button type="button" className="btn btn-primary">Save changes</button>
                </div>
              </div>
            </div>
          </div>
        )
    },
    propTypes:{
        handleHideModal: React.PropTypes.func.isRequired
    }
});



let App = React.createClass({
    getInitialState(){
        return {view: {showModal: false}}
    },
    handleHideModal(){
        this.setState({view: {showModal: false}})
    },
    handleShowModal(){
        this.setState({view: {showModal: true}})
    },
    render(){
    return(
        <div className="row">
            <button className="btn btn-default btn-block" onClick={this.handleShowModal}>Open Modal</button>
            {this.state.view.showModal ? <Modal handleHideModal={this.handleHideModal}/> : null}
        </div>
    );
  }
});

React.render(
   <App />,
    document.getElementById('container')
);

The main idea is to only render the Modal component into the React DOM when it is to be shown (in the App components render function). I keep some 'view' state that indicates whether the Modal is currently shown or not.

The 'componentDidMount' and 'componentWillUnmount' callbacks either hide or show the modal (once it is rendered into the React DOM) via Bootstrap javascript functions.

I think this solution nicely follows the React ethos but suggestions are welcome!

Answer from tgrrr on Stack Overflow
🌐
React Bootstrap
react-bootstrap.netlify.app › modals
Modals | React Bootstrap
... You can use the fullscreen prop to make the modal fullscreen. Specifying a breakpoint will only set the modal as fullscreen below the breakpoint size. ... You can apply custom css to the modal dialog div using the dialogClassName prop. Example is using a custom css class with width set to 90%.
🌐
MDBootstrap
mdbootstrap.com › standard › modal
React Modal with Bootstrap - free examples & tutorial
Below is a live demo followed by example HTML and JavaScript. For more information, read the modal API/events doc for details on relatedTarget. ... Show a second modal and hide this one with the button below. ... Hide this modal and show the first with the button below. ... import React, { useState } from 'react'; import { MDBBtn, MDBModal, MDBModalDialog, MDBModalContent, MDBModalHeader, MDBModalTitle, MDBModalBody, MDBModalFooter, } from 'mdb-react-ui-kit'; export default function App() { const [toggleOneModal, setToggleOneModal] = useState(false); const [toggleTwoModal, setToggleTwoModal] =
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › react-bootstrap-modal-component
React-Bootstrap Modal Component - GeeksforGeeks
March 7, 2024 - Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code. ... import React from 'react'; import 'bootstrap/dist/css/bootstrap.css'; import Modal from 'react-bootstrap/Modal'; import Button from 'react-bootstrap/Button'; export default function App() { return ( <div style={{ display: 'block', width: 700, padding: 30 }}> <h4>React-Bootstrap Modal Component</h4> <Modal.Dialog> <Modal.Header closeButton> <Modal.Title> Sample Modal Heading </Modal.Title> </Modal.Header> <Modal.Body> <p> This is the sample text for our Modal </p> </Modal.Body> <Modal.Footer> <Button variant="primary"> Save changes </Button> <Button variant="secondary"> Close </Button> </Modal.Footer> </Modal.Dialog> </div> ); }
🌐
Pluralsight
pluralsight.com › blog › guides
Working with Bootstrap's Modals in React | Online Courses, Learning ...
import Modal from "react-bootstrap/Modal"; import "bootstrap/dist/css/bootstrap.min.css"; A modal has a few basic sections: the Header, the Title, the Body, and the Footer. These sections will hold the content that we need to display. Here's an example displaying a basic modal using these components.
🌐
Medium
medium.com › nerd-for-tech › how-to-get-a-react-bootstrap-modal-to-open-and-close-using-a-button-of-your-choice-in-a-p-cde3ef6c0d4c
How to get a React Bootstrap Modal to open and close using a button of your choice in a parent component | by Sharad Satsangi | Nerd For Tech | Medium
May 5, 2021 - Now, when a user clicks the Tab marked Show the Modal!, they’ll open up the Modal, and when they click the x or close buttons on the component the Modal will close. Easy-peasy. React-Bootstrap is one of many custom frameworks freely available to power-up our frontend development needs.
🌐
CodeSandbox
codesandbox.io › examples › package › react-bootstrap-modal
react-bootstrap-modal examples - CodeSandbox
Use this online react-bootstrap-modal playground to view and fork react-bootstrap-modal example apps and templates on CodeSandbox.
Top answer
1 of 12
103

I was recently looking for a nice solution to this without adding React-Bootstrap to my project (as Bootstrap 4 is about to be released).

This is my solution: https://jsfiddle.net/16j1se1q/1/

let Modal = React.createClass({
    componentDidMount(){
        $(this.getDOMNode()).modal('show');
        $(this.getDOMNode()).on('hidden.bs.modal', this.props.handleHideModal);
    },
    render(){
        return (
          <div className="modal fade">
            <div className="modal-dialog">
              <div className="modal-content">
                <div className="modal-header">
                  <button type="button" className="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                  <h4 className="modal-title">Modal title</h4>
                </div>
                <div className="modal-body">
                  <p>One fine body&hellip;</p>
                </div>
                <div className="modal-footer">
                  <button type="button" className="btn btn-default" data-dismiss="modal">Close</button>
                  <button type="button" className="btn btn-primary">Save changes</button>
                </div>
              </div>
            </div>
          </div>
        )
    },
    propTypes:{
        handleHideModal: React.PropTypes.func.isRequired
    }
});



let App = React.createClass({
    getInitialState(){
        return {view: {showModal: false}}
    },
    handleHideModal(){
        this.setState({view: {showModal: false}})
    },
    handleShowModal(){
        this.setState({view: {showModal: true}})
    },
    render(){
    return(
        <div className="row">
            <button className="btn btn-default btn-block" onClick={this.handleShowModal}>Open Modal</button>
            {this.state.view.showModal ? <Modal handleHideModal={this.handleHideModal}/> : null}
        </div>
    );
  }
});

React.render(
   <App />,
    document.getElementById('container')
);

The main idea is to only render the Modal component into the React DOM when it is to be shown (in the App components render function). I keep some 'view' state that indicates whether the Modal is currently shown or not.

The 'componentDidMount' and 'componentWillUnmount' callbacks either hide or show the modal (once it is rendered into the React DOM) via Bootstrap javascript functions.

I think this solution nicely follows the React ethos but suggestions are welcome!

2 of 12
65

You can use React-Bootstrap (https://react-bootstrap.github.io/components/modal). There is an example for modals at that link. Once you have loaded react-bootstrap, the modal component can be used as a react component:

var Modal = ReactBootstrap.Modal;

can then be used as a react component as <Modal/>.

For Bootstrap 4, there is react-strap (https://reactstrap.github.io). React-Bootstrap only supports Bootstrap 3.

🌐
npm
npmjs.com › package › react-bootstrap-modal
react-bootstrap-modal - npm
transition Boolean(default true) Fade the entry and exit of the modal. You can also provide a Transition component from the react-transition-group v2 library to customize the animation more minutely.
      » npm install react-bootstrap-modal
    
Published   Sep 24, 2018
Version   4.2.0
Author   Jason Quense
Find elsewhere
🌐
React-bootstrap
react-bootstrap.github.io › react-overlays › api › Modal
Modal
To do this, we use a common technique of applying the aria-hidden='true' attribute to the non-Modal elements in the Modal container. This means that for a Modal to be truly modal, it should have a container that is outside your app's React hierarchy (such as the default: document.body).
Top answer
1 of 1
1

Hi very simple you need to use this component in your HintComponent and pass a prop showModal={true} but before this, you need to receive that prop in your modal component and set it in state using React.useEffect

So your final code will be like below:

ModalComponent

import React, {useState} from 'react';
import Button from 'react-bootstrap/Button';
import Modal from 'react-bootstrap/Modal';
import render from 'react-dom';

function Example(props) {
  const {showModal = false, onClose = ()=>{}} = props;
  const [show, setShow] = useState(showModal);

  React.useEffect(()=>{
    setShow(showModal);
  },[showModal]);

  const handleClose = () => {
   setShow(false);
   // just to have custom function for modal close which will be used can be used in HintComponent maybe you want to perform somehting else after modal close.
   typeof onClose === 'function' && onClose();
  };
  const handleShow = () => setShow(true);

  return (
    <>
      <Button variant="primary" onClick={handleShow}>
        Launch demo modal
      </Button>

      <Modal show={show} onHide={handleClose}>
        <Modal.Header closeButton>
          <Modal.Title>Modal heading</Modal.Title>
        </Modal.Header>
        <Modal.Body>Woohoo, you're reading this text in a modal!</Modal.Body>
        <Modal.Footer>
          <Button variant="secondary" onClick={handleClose}>
            Close
          </Button>
          <Button variant="primary" onClick={handleClose}>
            Save Changes
          </Button>
        </Modal.Footer>
      </Modal>
    </>
  );
}

render(<Example />);

I would recommend do not manage Modal visibility in its component but control it from the parent component in your case HintComponent.

🌐
Javatpoint
javatpoint.com › react-bootstrap-modal
React Bootstrap Modal - javatpoint
The alerts have a different color to specify a message. For example, to display a success message, we use green color, and for a danger message, we use red color. The Bootstrap alerts are designed in a... ... React Bootstrap's Grid system is similar to the traditional Bootstrap Grid system.
🌐
Trimble
modus-react-bootstrap.trimble.com › components › modals
Modals | Trimble Modus React Bootstrap Developer Guide
You can specify a bootstrap large or small modal by using the "size" prop.These sizes kick in at certain breakpoints to avoid horizontal scrollbars on narrower viewports. import Modal from `@trimbleinc/modus-react-bootstrap/Modal`
🌐
GitHub
github.com › jquense › react-bootstrap-modal
GitHub - jquense/react-bootstrap-modal: React port of jschr's better bootstrap modals
If you do not like the Bootstrap visual look and feel, you can adjust variables.less to suit your needs and transpile it to css yourself. The main Modal Component. show: Boolean(default false) make the Modal visible or hidden
Starred by 88 users
Forked by 50 users
Languages   JavaScript 68.1% | CSS 31.9% | JavaScript 68.1% | CSS 31.9%
🌐
DEV Community
dev.to › kimmese › react-bootstrap-modal-form-31gc
React Bootstrap Modal Form - DEV Community
January 25, 2021 - Import React-Bootstrap Components. Show/Hide a Modal Form.
🌐
C# Corner
c-sharpcorner.com › article › how-to-create-boostrap-modal-in-reactjs
How To Create Boostrap Modal In ReactJs
December 1, 2021 - In this article, we will learn to create a new ReactJs project using npm new command, After that, we will explain how to create Reactjs bootstrap modal in Visual Studio code. Now we will start by creating a new project. ... Create a React project setup using the below commands or however, you create your React app. npx create-react-app projectname Example, npx create-react-app sample-modal
🌐
Pluralsight
pluralsight.com › blog › guides
How to Trigger Modal for React Bootstrap | Online Courses, Learning ...
In this guide, you will learn how to trigger a React Bootstrap Modal programmatically using state.
🌐
Ordinarycoders
ordinarycoders.com › blog › article › react-bootstrap-modal
How to Make A React Bootstrap Modal
Bootstrap modals by … ... June 28, 2021, 8:29 p.m. ... Adding a React "Copy to Clipboard" function is easy enough. It can be done inline or called as a method. Basic… ... June 23, 2021, 1:58 a.m. ... Have you ever indulged or associated with your brand or someone’s business? So what are the pros and cons you&r… ... June 22, 2021, 5:55 p.m. ... Here are 7 examples ...
🌐
CoreUI
coreui.io › react › documentation › components › modal › bootstrap
React Bootstrap Modal Component - CoreUI
October 21, 2025 - It's fully customizable and accessible, with support for animations, scrollable content, multiple sizes, and more. This static modal example shows the structure of a modal with header, body, ...
🌐
Codú
codu.co › articles › creating-a-pop-up-modal-dialog-in-bootstrap-react-xgeujzcj
Creating a Reusable Modal Dialog in React Bootstrap | by tony-albanese | Codú
The first thing we want to do is create a file called ModalAlert.jsx and store it in an appropriate folder in your project - ie wherever you store files for your components and add the following. (I have exaggerated spacing for readability.) // (1) The imports import React from 'react'; import Button from 'react-bootstrap/Button'; import Modal from 'react-bootstrap/Modal'; //(2) props function ModalAlert({show, handleClose, onConfirm, title, message, buttonLabel}) { return ( //(3) Declare Modal component.
🌐
npm
npmjs.com › package › react-modal-bootstrap
react-modal-bootstrap - npm
<script src="path/to/react-modal-bootstrap/dist/react-modal-bootstrap.js"></script> ... View demo or example folder.
      » npm install react-modal-bootstrap
    
Published   Mar 21, 2017
Version   1.1.1
Author   Minh Tran