ReactJs: Is it possible to render DOM to document by class name?

前端 未结 1 1238
后悔当初
后悔当初 2021-01-03 03:51

I\'m learning ReactJs and really like it. I wanted to ask if we can render virtual DOM to document by class name.

React.render(
    

        
相关标签:
1条回答
  • 2021-01-03 04:32

    It seems you have used a wrong method.

    Probably you should use getElementsByClassName instead of getElementByClassName. And DO NOT forget getElementsByClassName returns an array-like obj HTMLCollection, so picking the first element is necessary.

    React.render(
      <CommentBox url="data/comments.json" pollInterval={2000} />,
      document.getElementsByClassName('className')[0]
    );
    

    For more infomation, check out the docs.

    0 讨论(0)
提交回复
热议问题