'use client'; import type { ColumnDef } from '@tanstack/react-table'; import { flexRender, getCoreRowModel, useReactTable, } from '@tanstack/react-table'; import { Trans } from '../makerkit/trans'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from './table'; interface DataTableProps { columns: ColumnDef[]; data: TData[]; } export function DataTable({ columns, data, }: DataTableProps) { // TODO: remove when https://github.com/TanStack/table/issues/5567 gets fixed 'use no memo'; const table = useReactTable({ data, columns, getCoreRowModel: getCoreRowModel(), }); return (
{table.getHeaderGroups().map((headerGroup) => ( {headerGroup.headers.map((header) => { return ( {header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext(), )} ); })} ))} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( )}
); }