korbit-ai[bot] commented on code in PR #35866:
URL: https://github.com/apache/superset/pull/35866#discussion_r2468782776
##########
superset-frontend/packages/superset-ui-core/src/components/TableCollection/index.tsx:
##########
@@ -280,6 +285,9 @@ function TableCollection<T extends object>({
sortDirections={['ascend', 'descend', 'ascend']}
isPaginationSticky={isPaginationSticky}
showRowCount={showRowCount}
+ rowClassName={(record: Record<string, unknown>) =>
+ record?.id === highlightRowId ? 'table-row-highlighted' : ''
+ }
Review Comment:
### Inline function causes unnecessary row re-renders <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The rowClassName function is recreated on every render, causing unnecessary
re-renders of all table rows.
###### Why this matters
This will trigger React to re-render every table row on each component
update, even when highlightRowId hasn't changed, leading to poor performance
especially with large datasets.
###### Suggested change ∙ *Feature Preview*
Wrap the rowClassName function with useCallback to memoize it and prevent
unnecessary re-renders:
```typescript
const getRowClassName = useCallback(
(record: Record<string, unknown>) =>
record?.id === highlightRowId ? 'table-row-highlighted' : '',
[highlightRowId]
);
// Then use it in the component:
rowClassName={getRowClassName}
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c3555468-176c-4e65-a3f2-6eea0974f16f/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c3555468-176c-4e65-a3f2-6eea0974f16f?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c3555468-176c-4e65-a3f2-6eea0974f16f?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c3555468-176c-4e65-a3f2-6eea0974f16f?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/c3555468-176c-4e65-a3f2-6eea0974f16f)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:95f8dfec-102d-4ff9-afe0-ffc827116c7a -->
[](95f8dfec-102d-4ff9-afe0-ffc827116c7a)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]