When you call this.$modal.modal('show') , it will actually rebuild your DOM, and React will not be happy about it. In addition, if you try to establish control in your modal mode, the control will not work.
What you need to do is React.render the modal already shown , i.e. modal with markup, as if $('.ui.modal').modal('show') called.
Here is my attempt to use React-Portal to help render the reactive component at the body level. You can use your method if you want.
// modal.jsx import React, { Component } from 'react'; import Portal from 'react-portal'; class InnerModal extends Component { constructor(props) { super(props); this.state = { modalHeight: 0 }; } componentDidMount() { let modalHeight = window.$('#reactInnerModal').outerHeight(); this.setState({modalHeight: modalHeight}); } render() { return ( <div id='reactInnerModal' className='ui standard test modal transition visible active' style={{'margin-top': - this.state.modalHeight / 2}}> <i className='close icon' onClick={this.props.closePortal}></i> {this.props.children} </div> ); } } class Modal extends Component { render() { let triggerButton = <button className='ui button'>Open Modal</button>; return ( <Portal className='ui dimmer modals visible active page transition' openByClickOn={triggerButton} closeOnEsc={true} closeOnOutsideClick={true}> <InnerModal> {this.props.children} </InnerModal> </Portal> ); } } export default Modal;
Please note that my modal code has already been displayed in the markup.
Then you can use the modal form as shown below:
// index.jsx import React, { Component } from 'react'; import Modal from './modal'; class ModalDemo extends Component { render() { return ( <Modal> <div className='header'> Profile Picture </div> <div className='image content'> <div className='ui medium image'> <img src='http://semantic-ui.com/images/avatar2/large/rachel.png' /> </div> <div className='description'> <div className="ui header">We've auto-chosen a profile image for you.</div> <p>We've grabbed the following image from the <a href='https://www.gravatar.com' target='_blank'>gravatar</a> image associated with your registered e-mail address.</p> <p>Is it okay to use this photo?</p> </div> </div> <div className='actions'> <div className='ui black deny button'> Nope </div> <div className='ui positive right labeled icon button'> Yep, that me <i className='checkmark icon'></i> </div> </div> </Modal> ); } } React.render(<ModalDemo />, document.getElementById('content'));
With this, you should not crack your way into DOM manipulation using jQuery, and modal control (button, link, etc. for calling functions) still works.
Hope this help!
source share