【问题标题】:Uncaught Type error in React JS [duplicate]React JS中未捕获的类型错误[重复]
【发布时间】:2017-12-14 05:38:35
【问题描述】:

当我打开我的 html 文件时,我收到以下错误消息。

TypeError: undefined is not a function (near
'..._react2.default.createClass...')
(anonymous function)bundle.js 966
_webpack_require bundle.js 20
(anonymous function)bundle.js 73
_webpack_require bundle.js 20
(anonymous function)bundle.js 63
_webpack_require bundle.js 64

这是我的 HTML 代码

</head>
<body>
    <div id="content"></div>
    <script src="js/bundle.js"></script>
</body>
</html>

这是我的 app.js 文件 import firstComponent from './firstComponent'

这是我的第一个 component.js 文件

import React from 'react'
import ReactDOM from 'react-dom'
var CommentBox=React.createClass({
 render:function(){
   return(
      <div className="CommentBox">
                HelloWorldCommentBox
      </div>
   );
   }
  });
  ReactDOM.render(
  <commentBox/>,
       document.getElementById('content')
  );

请帮帮我

【问题讨论】:

  • commentBox 应该是CommentBox
  • @Rajesh 为什么?我怀疑错误来自 createClass 在 16 中被删除的事实
  • @Li357 我不知道。
  • @Rajesh 在 15 中被弃用并被正式移除,见“打包”:reactjs.org/blog/2017/09/26/react-v16.0.html

标签: javascript reactjs


【解决方案1】:

组件的名称必须以大写字母开头,并且在使用组件时必须使用相同的名称。

组件是

&lt;CommentBox/&gt;

不是

&lt;commentBox/&gt;

【讨论】:

    猜你喜欢
    • 2020-12-11
    • 2013-07-23
    • 1970-01-01
    • 2015-07-20
    • 2023-01-26
    • 2017-10-15
    • 2023-04-04
    相关资源
    最近更新 更多