How to open/close react-bootstrap modal programmatically?

后端 未结 4 443
心在旅途
心在旅途 2020-12-14 07:30

I need to open/close modal like

$(element).modal(\'show\')

How to do that?

4条回答
  •  离开以前
    2020-12-14 08:10

    Your modal will have a show prop and an onHide prop to determine when it's displayed. E.g.:

    
    

    The onHide function simply changes showModal state property. Your modal is shown/hidden based on the parent's state:

    close(){
      this.setState({ showModal: false });
    }
    

    If you'd like to close the modal from within the modal itself, you can trigger the onHide function defined on the parent via props. For example, this is a button somewhere inside the modal closing it:

    
    

    Here is a fiddle simulating this workflow.

提交回复
热议问题