Getting DOM node from React child element

后端 未结 6 1458
余生分开走
余生分开走 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 17:55

    You can do this using the new React ref api.

    function ChildComponent({ childRef }) {
      return 
    ; } class Parent extends React.Component { myRef = React.createRef(); get doSomethingWithChildRef() { console.log(this.myRef); // Will access child DOM node. } render() { return ; } }

提交回复
热议问题