Reactjs 如何将react元素转换为HTML

Reactjs 如何将react元素转换为HTML,reactjs,Reactjs,TestComponent的使用 <TestComponent testContent= { <div> <p>sometxt <a href="#">link1</a><p> <p>hello how was your day</p> <p>some other txt <a href="#">link1</a>

TestComponent的使用

 <TestComponent
   testContent= {
     <div>
       <p>sometxt <a href="#">link1</a><p>
       <p>hello how was your day</p>
       <p>some other txt <a href="#">link1</a><p>
     </div>
   }
 />

class TestComponent extends React.Component {
  constructor(props) {
    const testContent = props.testContent;
  }
}

类TestComponent扩展了React.Component{
建造师(道具){
const testContent=props.testContent;
}
}
在上面的组件代码中,在构造函数中,当我尝试访问props.testContent时。它的类型是react元素。但是,我想查询内容以查找可聚焦的元素,例如:在本例中。由于prop值为react元素,因此无法使用querySelector()。所以我需要将这个react元素转换为HTML元素

有谁能帮我知道我怎样才能做到这一点。 非常感谢您的帮助


谢谢

在您的示例中,还没有HTML元素(也称为DOM节点)——在将组件装入DOM之前,HTML元素是不存在的。完成后,您可以使用
ReactDOM.findDOMNode()
(请参阅)或
ref
(请参阅)访问元素


您需要在
componentDidMount
componentdiddupdate
React生命周期方法中执行此步骤。(请参阅)

谢谢您的回复。没错@ReactDOM.findDOMNode()在将组件装入DOM后非常有用。然而,在这里,我想从props值中查询,以获取构造函数中的可fousable元素,这是在装入DOM之前。你有什么建议吗。谢谢我唯一能想到的就是使用这样一个库:它提供了一个“类似DOM”的结构。它可以让你做你需要的事。