【发布时间】:2020-03-12 11:07:06
【问题描述】:
我是新手,我正在尝试使用参数构建自定义组件。
我只是想知道这样做的确切方法是什么。
这是我当前的代码,我应该如何将这些 Columns、ajax 和 datasource 传递给组件。
还是我做错了?
import * as React from 'react';
interface Column {
name: string,
header: string,
value: Function
}
export default class DataTable extends React.PureComponent<({
dataSource: any[],
ajax: string
columns: Column[]
onEdit: Function,
onDelete: Function
})>{
public state = {
dataSource: [],
ajax: undefined,
columns: [],
onEdit: undefined,
onDelete: undefined
}
componentDidMount() {
if (this.state.ajax != undefined) {
fetch(this.state.ajax)
.then(response => response.json())
.then(data => this.setState({ dataSource: data }));
}
}
render() {
var template = (
<table className="table">
<thead className="thead-darked">
{
this.state.columns.map((x: Column) => {
<th scope="col">{x.header}</th>
})
}
</thead>
</table>)
return template;
}
}
【问题讨论】:
标签: javascript reactjs typescript asp.net-core react-redux