【发布时间】:2016-08-24 12:42:43
【问题描述】:
我正在尝试使用 react 来重新创建我的当前组件(用纯打字稿编写),但我找不到一种方法来为扩展另一个组件的组件提供额外的道具。
export interface DataTableProps {
columns: any[];
data: any[];
}
export class DataTable extends React.Component<DataTableProps, {}> {
render() {
// -- I can use this.props.columns and this.props.data --
}
}
export class AnimalTable extends DataTable {
render() {
// -- I would need to use a this.props.onClickFunction --
}
}
我的问题是我需要给 AnimalTable 一些与 DataTable 无关的道具。我怎样才能做到这一点 ?
【问题讨论】:
-
考虑使用
abstract类/函数。 (see answer below)
标签: reactjs typescript