The problem is that inside your Table
component you change columns
to render a tooltip, but you do this after your useTable
call.
So a simple fix would be to put this logic before the useTable
call:
function Table({ columns, data }) {
for (let i = 0; i < columns.length; i++) {
columns[i].columns = columns[i].columns.map((column) => ({
...column,
Cell: ({ value }) => {
return (
<div>
<Tippy content="Tooltip content">
<span>{value}</span>
</Tippy>
</div>
);
},
}));
}
const {
getTableProps,
getTableBodyProps,
headerGroups,
rows,
prepareRow,
} = useTable({
columns,
data,
});
return (
<table {...getTableProps()}>
<thead>
{headerGroups.map((headerGroup) => (
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((column) => (
<th {...column.getHeaderProps()}>{column.render("Header")}</th>
))}
</tr>
))}
</thead>
<tbody {...getTableBodyProps()}>
{rows.map((row, i) => {
prepareRow(row);
return (
<tr {...row.getRowProps()}>
{row.cells.map((cell) => {
return <td {...cell.getCellProps()}>{cell.render("Cell")}</td>;
})}
</tr>
);
})}
</tbody>
</table>
);
}
sandbox example