import { type ColumnDef, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table"; type DataTableProps = { data: T[]; // eslint-disable-next-line @typescript-eslint/no-explicit-any columns: ColumnDef[]; onRowClick?: (row: T) => void; selectedRowId?: string; getRowId?: (row: T) => string; className?: string; wrapClassName?: string; }; export function DataTable({ data, columns, onRowClick, selectedRowId, getRowId, className, wrapClassName, }: DataTableProps) { // TanStack Table returns mutable table helpers; React Compiler intentionally skips memoizing here. // eslint-disable-next-line react-hooks/incompatible-library const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), getRowId, }); return (
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => ( ))} ))} {table.getRowModel().rows.map((row) => { const isSelected = selectedRowId != null && row.id === selectedRowId; return ( onRowClick(row.original) : undefined} > {row.getVisibleCells().map((cell) => ( ))} ); })}
{header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
{flexRender(cell.column.columnDef.cell, cell.getContext())}
); }