Bootstrap modal in React.js

前端 未结 12 1374
别跟我提以往
别跟我提以往 2020-12-02 07:19

I need to open a Bootstrap Modal from clicking on a button in a Bootstrap navbar and other places (to show data for a component instance, ie. providing \"editing\" f

12条回答
  •  旧巷少年郎
    2020-12-02 08:10

    getDOMNode() is deprecated. Instead use ref to access DOM element. Here is working Modal component (Bootstrap 4). Decide whether to show or not to show Modal component in parent component.

    Example: https://jsfiddle.net/sqfhkdcy/

    class Modal extends Component {
        constructor(props) {
            super(props);
        }
        componentDidMount() {
            $(this.modal).modal('show');
            $(this.modal).on('hidden.bs.modal', handleModalCloseClick);
        }
        render() {
            return (
                
    this.modal = modal} id="exampleModal" tabIndex="-1" role="dialog" aria- labelledby="exampleModalLabel" aria-hidden="true">
    Modal title
    ...
    ); } }

    Edit:

    Here are the necessary imports to make it work:

    import $ from 'jquery';
    window.jQuery = $;
    window.$ = $;
    global.jQuery = $;
    

提交回复
热议问题