Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  57] [ 3]  / answers: 1 / hits: 12053  / 5 Years ago, thu, july 25, 2019, 12:00:00

I get an error.
I have added some code and would like to my code to get to know why
its not working.
I can't use react-strap. Please suggest if we can use Bootstrap modal in react.


I get an error.
I have added some code and would like to my code to get to know why
its not working.
I can't use react-strap. Please suggest if we can use Bootstrap modal in react.
Below is my code


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

class Modal extends React.Component {
constructor(props) {
super(props);
}

componentDidMount() {
$('#myModal').on('shown.bs.modal', function () {
$('#myInput').trigger('focus');
});
}

render()
{
return (
<div>
<div className="bd-example">
//Button code
<button type="button" className="btn btn-primary " data-toggle="modal" data-target="#exampleModalLive">
Launch demo modal</button>

//Modal code
<div className="modal" id="exampleModalLive" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div className="modal-dialog modal-dialog-centered" role="document">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title" id="exampleModalCenterTitle">Modal title</h5>
<button type="button" className="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div className="modal-body">
...
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" className="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</div>
</div>
);
}
}
export default Modal;

More From » jquery

 Answers
3

You can include jquery and bootstrap using CDN in index.html file which is in public folder.



<script src=https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js></script>
<script src=https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js></script>


Also make sure you have added bootstrap.css file,



<link rel=stylesheet href=https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css>


Demo


[#6793] Tuesday, July 23, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
minab

Total Points: 701
Total Questions: 104
Total Answers: 91

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;