【发布时间】:2021-07-26 15:41:30
【问题描述】:
对于 React 来说还是相当新的,有一个奇怪的语法问题。我正在创建一个 React 组件,我相信我有正确的打开/关闭 { & },但我想我一定是因为它抛出的错误而遗漏了一些东西?这是我的代码。
import React from 'react';
import { TreeList, SearchPanel, Scrolling, Lookup } from 'devextreme-react/tree-list';
import 'devextreme-react/text-area';
import 'whatwg-fetch';
import WireGrid from '../WireGrid.js'
const expandedRowKeys = [1];
// const allowedPageSizes = [5, 10, 15, 20];
class WireTree extends React.Component {
constructor(props) {
super(props)
this.state = {
jsonData: null
}
this.onFocusedRowChanged = this.onFocusedRowChanged.bind(this)
}
async componentDidMount() {
const url = "http://localhost:4741/wiretree";
const response = await fetch(url);
const data = await response.json();
this.setState({
'jsonData' : data.recordset
})
}
onFocusedRowChanged(e) {
var rowData = e.row && e.row.data,
cellValue
if(rowData) {
cellValue = e.component.cellValue(e.row.rowIndex, 'Filter');
module.export = cellValue
if (!cellValue) {
return null;
} else {
console.log('cellValue: ', cellValue)
// <WireGrid />
}
}}
}
render() {
return (
<TreeList
id="wireTree"
dataSource={this.state.jsonData}
dataStructure="plain"
rootValue=""
defaultExpandedRowKeys={expandedRowKeys}
columnAutoWidth={true}
keyExpr="categoryID"
parentIdExpr="ParentID"
wordWrapEnabled={true}
focusedRowEnabled={true}
virtualModeEnabled={true}
onFocusedRowChanged={this.onFocusedRowChanged}
>
<SearchPanel visible={true} />
<Scrolling mode="standard" />
<Lookup
dataSource={this.state.jsonData}
valueExpr="ID"
displayExpr="Search" />
</TreeList>
);
}
export default WireTree;
这是它在控制台中显示的错误,它指向 'render() {' 行:
';' expected. ts(1005) [42, 10]
不是 ts = TypeScript 吗?有什么想法吗?
【问题讨论】:
-
你在渲染函数之前的
}太多了。 -
使用好的编辑器,它会在检测到错误的确切位置提醒您。
-
@Taxel 哦,有趣 - 我以为你应该在组件之外调用渲染/返回?
标签: javascript reactjs react-hooks react-component