user1547174 user1547174 - 1 month ago 22x
React JSX Question

Listen for bootstrap modal close event in reactjs

is there a way I can listen for a bootstrap modal closing? In pure jQuery I would do something like:

$('#myModal').on('', function () {
// do something…

However, what would be the appropriate way to do it in react?

Thanks in advance!


the below code will give you the idea, as You can control whether the modal is shown using this.setState({showModal: true}) to achieve the equivalent of what you asked for in your post in the example below

const ControlledModalExample = React.createClass({

  return { showModal: false };

  this.setState({ showModal: false });

  this.setState({ showModal: true });

render() {
  return (
      <Button onClick={}>
        Launch modal

    <Modal show={this.state.showModal} onHide={this.close}>
      <Modal.Header closeButton>
        <Modal.Title>Modal heading</Modal.Title>
        <div>Modal content here </div>
        <Button onClick={this.close}>Close</Button>

you can get more information from the below doc url,