reactjs - 未捕获(承诺中)TypeError:无法将类作为函数调用
问题描述
我最近将我的 babel 版本升级到了最新版本。更新后,我的反应应用程序中的 babel 无法识别普通类,并且我遇到了错误。
未捕获(承诺中)TypeError:无法将类作为函数调用
.babelrc
{
"presets": [
"env",
"react"
],
"plugins": [
"transform-class-properties",
"transform-object-rest-spread"
]
}
我的应用程序中的 babel 相关库:
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
"babel-jest": "^22.4.3",
"babel-loader": "^7.1.5",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1"
babel 看不懂这个类
CRUDTree.js
const resourceBoxWidth = 225;
const resourceBoxHeight = 85;
const halfBoxWidth = resourceBoxWidth / 2;
const halfBoxHeight = resourceBoxHeight / 2;
const urlLeftMargin = 10;
const urlFontSize = 12;
const fullPathFontSize = 10;
export default class{
static resourceBoxWidth() { return resourceBoxWidth; }
static resourceBoxHeight() { return resourceBoxHeight; }
static halfBoxHeight() { return halfBoxHeight; }
static halfBoxWidth() { return halfBoxWidth; }
}
APITree.js
import React, { Component } from 'react';
import CRUDTree from './CRUDTree';
class extends Component{
render(){
return(
<CRUDTree data={
[
this.state.treedata,
this.onClick,
{
x: this.state.offsetX,
y: this.state.offsetY
}
]}
width={400} height={500}
options={{
border: "2px solid black",
margin: {
top: 0,
bottom: 0,
left: 50,
right: 0
}
}
} />
)
}
}
解决方案
如果你CRUDTree
是一个 React 组件(对我来说似乎是这样),那么你定义它是错误的。你错过了这个extends
部分。
export default class extends React.Component {
....
}
推荐阅读
- java - 如何使用 gradle bnd (bndtools) 将“Embedded-Artifacts”部分添加到 Manifest?
- typescript - 如何检查数组是否在打字稿中包含空值?
- python - 在作为字典列表的数据框列中,如何使用逗号连接值,并将每个嵌套键作为新列?
- elasticsearch - Filebeat - 以 key=value 格式发送和处理配置文件
- javascript - 当新客户端订阅而不是最后一条消息时如何获取所有消息(mqtt,保留)
- ios - IAP 处理多用户/原始交易 ID
- entity-framework-core - 非默认外键关系
- python - 无法使用 Python 连接到 Apache CouchDb - InvalidURL Nonnumeric port Exception
- reactjs - 反应路线没有呈现
- oracle - 使用交换变量 PLSQL 时出错