The modal module of antd is used in react. How to get a dom element in modal if you want to get it?

want to embed a plug-in in modal, but you need to get the dom node tag. How to get the
ref and ReactDOM.findDOMNode methods have been tried, and the result is null

parent component:
< AddUserWin ref= "AddUserWin" visible= {state.visible} title= {state.title} hideModal= {me.hideModal} record= {state.record}
canEdit= {state.canEdit} / >

Sub-component modal module:
< Modal title= {props.title} visible= {props.visible} onCancel= {this.handleCancel} width= "900" footer= {modalBtns} >

      <Form horizontal  form={this.props.form}>
              <div ref={(ref) => this._div = ref}></div>
              <div ref="edit"></div>

I use
var editor = ReactDOM.findDOMNode (this._div) or this.refs.edit
in the componentDidMount of the child component, the componentDidMount of the parent component and the modal method of the parent component. I have tried to get it when written outside modal. The code is as follows:

  <Modal title={props.title} visible={props.visible} onCancel={this.handleCancel} width="900"  footer={modalBtns} >
      <Form horizontal  form={this.props.form}>
  <div ref={(ref) => this._div = ref}></div>

at this time, ref"s div can be obtained, but what I need is really inside modal. I would like to ask the boss what method
look forward to getting dom tag elements. What I actually get is null
PS: stuck in the progress of the project. I am very urgent at present. I hope to get your help. If you can solve the problem, please have a cup of coffee. Thank you!


you can't get it during initialization because you always get the dom structure in the Modal in componentDidMount, but the current react,componentDidMount only executes once in the component's life cycle. When it is executed, the Modal component has not yet rendered, so naturally you cannot get the DOM structure in it.

now that you know why, you can think that since Modal is rendered only when the visibile attribute is true, you can't get DOM, at the beginning, so you must get it when the component is updated, so you can get the DOM structure in the componentDidUpdate function. I tried it, and the first time I couldn't get DOM, because of animation or other reasons, but I felt that I had to wait until the main thread was finished to get it. The method of rendering Modal should be in the main thread, so you can use setTimeout to put the logic of getting DOM elements into an asynchronous queue. This should be able to get, you try, I have tried to get, as shown in the picture.

dom dom form modal modal form dom

div refantd ref findDOMNode antd

ref ( findDOMNode form dom

I've seen it before. I add a setTimeout function where I need to call it, use its asynchronous mechanism to get the dom element, and then process