React/TypeScript: extending a component with additional properties

前端 未结 5 594
梦如初夏
梦如初夏 2021-02-01 16:05

I am trying to use react to recreate my currents components (written in pure typescript) but I can\'t find a way to give additional props to a component extending an other.

5条回答
  •  隐瞒了意图╮
    2021-02-01 16:29

    You'll need to make DataTable generic so that you'll be able to use an interface which extends DataTableProps:

    export interface AnimalTableProps extends DataTableProps {
        onClickFunction: Function;
    }
    
    export class DataTable extends React.Component { }
    
    export class AnimalTable extends DataTable {
        render() {
            // this.props.onClickFunction should be available
        }
    }
    

提交回复
热议问题