Invalid Component Element in React.JS

后端 未结 1 1041
情书的邮戳
情书的邮戳 2021-01-07 18:30

I\'ve been going through a react.js tutorial, with a simple hello world example. I can\'t find a reason why the following shouldn\'t work, but I keep getting this error.

相关标签:
1条回答
  • 2021-01-07 19:27

    You should pass to render <HelloWorld />, not new HelloWorld()

    React.render(<HelloWorld />, document.getElementById("test"))
    

    Example

    jsx-in-depth

    Or you can use React.createElement, like so

    React.render(React.createElement(HelloWorld, null), document.getElementById("test"))
    

    Example

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