Skip to content

Commit

Permalink
fix: avoid react key warnings in tables (#7694)
Browse files Browse the repository at this point in the history
Refactoring to get rid of `A props object containing a "key" prop is being spread into JSX` warning
  • Loading branch information
Tymek authored Jul 30, 2024
1 parent c828d01 commit b585ead
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,47 @@ export const SortableTableHeader = <T extends object>({
flex?: boolean;
}) => (
<TableHead className={className}>
{headerGroups.map((headerGroup) => (
<TableRow {...headerGroup.getHeaderGroupProps()} data-loading>
{headerGroup.headers.map((column: HeaderGroup<T>) => {
const content = column.render('Header');
{headerGroups.map((headerGroup) => {
const { key, ...props } = headerGroup.getHeaderGroupProps();
return (
<TableRow key={key} {...props} data-loading>
{headerGroup.headers.map((column: HeaderGroup<T>) => {
const content = column.render('Header');

return (
<CellSortable
// @ts-expect-error -- check after `react-table` v8
styles={column.styles || {}}
{...column.getHeaderProps(
column.canSort
? column.getSortByToggleProps()
: undefined,
)}
ariaTitle={
typeof content === 'string'
? content
: undefined
}
isSortable={Boolean(column.canSort)}
isSorted={column.isSorted}
isDescending={column.isSortedDesc}
maxWidth={column.maxWidth}
minWidth={column.minWidth}
width={column.width}
isFlex={flex}
isFlexGrow={Boolean(column.minWidth)}
// @ts-expect-error -- check after `react-table` v8
align={column.align}
>
{content}
</CellSortable>
);
})}
</TableRow>
))}
const { key, ...props } = column.getHeaderProps(
column.canSort
? column.getSortByToggleProps()
: undefined,
);

return (
<CellSortable
// @ts-expect-error -- check after `react-table` v8
styles={column.styles || {}}
key={key}
{...props}
ariaTitle={
typeof content === 'string'
? content
: undefined
}
isSortable={Boolean(column.canSort)}
isSorted={column.isSorted}
isDescending={column.isSortedDesc}
maxWidth={column.maxWidth}
minWidth={column.minWidth}
width={column.width}
isFlex={flex}
isFlexGrow={Boolean(column.minWidth)}
// @ts-expect-error -- check after `react-table` v8
align={column.align}
>
{content}
</CellSortable>
);
})}
</TableRow>
);
})}
</TableHead>
);
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,27 @@ export const VirtualizedTable = <T extends object>({

prepareRow(row);

const { key, ...props } = row.getRowProps({
style: { display: 'flex', top },
});

return (
<TableRow
hover
{...row.getRowProps({
style: { display: 'flex', top },
<TableRow {...props} hover key={key || row.id}>
{row.cells.map((cell) => {
const { key, ...props } = cell.getCellProps({
style: {
flex: cell.column.minWidth
? '1 0 auto'
: undefined,
},
});

return (
<TableCell key={key} {...props}>
{cell.render('Cell')}
</TableCell>
);
})}
key={row.id}
>
{row.cells.map((cell) => (
<TableCell
{...cell.getCellProps({
style: {
flex: cell.column.minWidth
? '1 0 auto'
: undefined,
},
})}
>
{cell.render('Cell')}
</TableCell>
))}
</TableRow>
);
})}
Expand Down

0 comments on commit b585ead

Please sign in to comment.