[React Typescript] Generics in Class Component

发布时间 2023-08-12 16:12:43作者: Zhentiw
interface TableProps<T> {
  rows: T[];
  renderRow: (row: T) => ReactNode;
}

export class Table<T> extends React.Component<TableProps<T>> {
  render(): ReactNode {
    return (
      <table>
        <tbody>
          {this.props.rows.map((row) => (
            <tr>{this.props.renderRow(row)}</tr>
          ))}
        </tbody>
      </table>
    );
  }
}