ColmunDef

export const commentColumns: ColumnDef<AdminEnCommentResDto>[] = [
  { accessorKey: 'id', header: '아이디' },
  { accessorKey: 'content', header: '컨텐츠' },
  { accessorKey: 'isDisplay', header: '불카운트' },
  {
    accessorKey: 'createdAt',
    header: '생성 일자',
    cell: ({ row }) => {
      const date = new Date(row.getValue('createdAt'));
      const formatted = date.toLocaleDateString();
      return <h1 className="text-blue-700">{formatted}</h1>;
    },
  },
];

기본 형태

import { ColumnDef, useReactTable } from '@tanstack/react-table';

const tableInstance = useReactTable({data, column});

return (
	<table>
		<thead>
			{tableInstance.getHeaderGroups().map((headerEl) => 
						(<TableRow key={headerEl.id}>
               {headerEl.headers.map((header) => {
                  return (
                    <TableHead key={header.id}>
                      {header.isPlaceholder ? null : flexRender(header.column.columnDef.header, header.getContext())}
                    </TableHead>
                  );
                })}
            </TableRow>)
		</thead>
	</table>
)

Header API

Body API

import {getCoreRowModel} from '@tanstack/react-table';

const tableInstance = useReactTable({
    data,
    columns,
    getCoreRowModel: getCoreRowModel()
  });
  
  
  
  return (
	<table>
		<thead>
			{...생략}
		</thead>
		<tbody>
			{tableInstance.getModel().rows.map((row) =>
				  <tr key={row.id} data-state={row.getIsSelected() && 'selected'}>
             {row.getVisibleCells().map((cell) => (
                <td key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</td>
              ))}
          </tr>
			)}
		</tbody>
	</table>
)