// Molecule (since it utilizes Text component, which is an atom) const Table = ({ cellPaddingSize, columns, data, hideHeader, onRowClick }) => { // Data passed to the useTable hook needs to be memoized // to avaid performance leaks const memoColumns = React.useMemo(() => columns, [columns]); const memoData = React.useMemo(() => data, [data]); const numOfColumns = React.useMemo(() => memoColumns.length, [memoColumns]); const defaultTableCellSize = getDefaultTableCellSize(numOfColumns); const handleRowClick = (row) => { onRowClick?.(row); }; const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow } = useTable({ columns: memoColumns, data: memoData, }); return (
{!hideHeader && ( {headerGroups.map((headerGroup) => ( // Apply the header row props {headerGroup.headers.map((column) => ( ))} ))} )} {rows.map((row) => { // Prepare the row for display prepareRow(row); return ( // Apply the row props handleRowClick(row)} {...row.getRowProps()} > {row.cells.map((cell) => ( ))} ); })}
{column.render('Header')}
{cell.render('Cell')}
); };