I'm using react-table in a NextJS project and I'm wondering how I can have more than one table on the same page. Been digging around but haven't found anything about it.
I have an instance on the page already and I'm not sure if I'm over thinking it but I was thinking I could just make a tableInstance2 but then, how would I tell the second table JSX to use that second batch of data?
const tableInstance = useTable({
columns: COLUMNS,
data: tableData
},
useSortBy);
const {
getTableProps,
getTableBodyProps,
headerGroups,
rows,
prepareRow
} = tableInstance;
Here is my current table markup:
{tableData.length > 0 &&
<div className={styles.tableSpace}>
<table {...getTableProps()} className={styles.table}>
<thead className={styles.thead}>
{headerGroups.map((headerGroup) => (
<tr {...headerGroup.getHeaderGroupProps()} className={styles.tr}>
{headerGroup.headers.map((column) => (
<th {...column.getHeaderProps(column.getSortByToggleProps())} className={styles.th}>
{column.render('Header')}
{column.Header !== 'Description' &&
<span>
{column.isSorted ? (column.isSortedDesc ? <FontAwesomeIcon className={styles.faCaretDown} icon={faCaretDown} /> : <FontAwesomeIcon className={styles.faCaretUp} icon={faCaretUp} />) : <FontAwesomeIcon className={styles.faArrowsAltV} icon={faArrowsAltV} />}
</span>
}
</th>
))}
</tr>
))}
</thead>
<tbody {...getTableBodyProps} className={styles.tbody}>
{rows.map(row => {
prepareRow(row)
return (
<tr {...row.getRowProps()} className={styles.tr}>
{row.cells.map((cell) => {
return (
<td {...cell.getCellProps()} className={styles.td}>
{cell.render('Cell')}
</td>
)
})}
</tr>
)
})}
</tbody>
</table>
</div>
}
Is having more than 1 on the same page (in the same file) possible? Would appreciate any tips. Thanks very much!