added missing keys for columns and rows

This commit is contained in:
Sebastian Sdorra
2019-12-12 10:32:51 +01:00
parent a973529328
commit 30a649ffe1

View File

@@ -37,9 +37,9 @@ const Table: FC<Props> = ({ data, sortable, children, emptyMessage }) => {
} }
}); });
const mapDataToColumns = (row: any) => { const mapDataToColumns = (row: any, rowIndex: number) => {
return ( return (
<tr> <tr key={rowIndex}>
{React.Children.map(children, (child, columnIndex) => { {React.Children.map(children, (child, columnIndex) => {
return <td>{React.cloneElement(child, { ...child.props, columnIndex, row })}</td>; return <td>{React.cloneElement(child, { ...child.props, columnIndex, row })}</td>;
})} })}
@@ -93,6 +93,7 @@ const Table: FC<Props> = ({ data, sortable, children, emptyMessage }) => {
onClick={isSortable(child) ? () => tableSort(index) : undefined} onClick={isSortable(child) ? () => tableSort(index) : undefined}
onMouseEnter={() => setHoveredColumnIndex(index)} onMouseEnter={() => setHoveredColumnIndex(index)}
onMouseLeave={() => setHoveredColumnIndex(undefined)} onMouseLeave={() => setHoveredColumnIndex(undefined)}
key={index}
> >
{child.props.header} {child.props.header}
{isSortable(child) && renderSortIcon(child, ascending, shouldShowIcon(index))} {isSortable(child) && renderSortIcon(child, ascending, shouldShowIcon(index))}