简体   繁体   中英

ReactJS Modal hide by jquery imported via NPM

I know I should not use jquery in my react app. But I will.

Now that we got that out of the way, I keep getting: __WEBPACK_IMPORTED_MODULE_4_jquery___default(...)(...).modal is not a function

I import jquery like this:

import $ from 'jquery';


class ReportTab extends Component {

    test(){
        $('#myModal').modal('hide')
    }

    render() {
        return (
        <div>
            <button onClick={this.test.bind(this}>Close</button>

            <div className="modal fade" id="myModal" role="dialog">
                <div className="modal-dialog">
                    <div className="modal-content">
                        <div className="report-daypicker-container">
                            <DayPicker onDayClick={this.test.bind(this)}/>
                        </div>
                        <div className="close-modal-container">
                            <button className="global-button global-button-active close-modal-btn" data-dismiss="modal">Cancel</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        )
    }
}

Try:

$('#myModal').hide();

If that doesn't work make sure you only have 1 element with the id myModal being rendered.

i think jquery is not enough for modal functions. For modal functions you must add jquery-ui to your component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM