Getting DOM node from React child element

后端 未结 6 1460
余生分开走
余生分开走 2020-12-04 17:14

Using the React.findDOMNode method that was introduced in v0.13.0 I am able to get the DOM node of each child component that was passed into a parent by mapping

6条回答
  •  暖寄归人
    2020-12-04 18:11

    This may be possible by using the refs attribute.

    In the example of wanting to to reach a

    what you would want to do is use is
    . Then you would be able to get that DOM node by using React.findDOMNode(this.refs.myExample).

    From there getting the correct DOM node of each child may be as simple as mapping over this.refs.myExample.children(I haven't tested that yet) but you'll at least be able to grab any specific mounted child node by using the ref attribute.

    Here's the official react documentation on refs for more info.

提交回复
热议问题