gpt4 book ai didi

javascript - React JS 中未捕获的类型错误

转载 作者:行者123 更新时间:2023-12-03 02:52:08 24 4
gpt4 key购买 nike

当我打开 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/>

关于javascript - React JS 中未捕获的类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47806528/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com