Skip to content

Commit 72d24ba

Browse files
committed
refactor(web): inline TableWrapper in BaseTable for hook safety
Remove module-level TableWrapper component and inline its mobile scroll support logic directly into renderRegularTable. Module-level components with hooks can cause issues when the module is loaded in certain contexts. The conditional ScrollArea wrapper for mobile devices is now part of the render function, maintaining the same functionality.
1 parent 76bc0fb commit 72d24ba

File tree

1 file changed

+36
-41
lines changed

1 file changed

+36
-41
lines changed

apps/web/src/components/tables/BaseTable.tsx

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,6 @@ interface BaseTableProps<T> {
4848
maxHeight?: number;
4949
}
5050

51-
// Helper component for table wrapper with mobile scroll support
52-
const TableWrapper = ({ children }: { children: React.ReactNode }) => {
53-
const { isMobile } = useResponsiveDesign();
54-
55-
if (isMobile()) {
56-
return (
57-
<ScrollArea
58-
type="auto"
59-
scrollbarSize={8}
60-
className={sprinkles({ borderGray3: true, borderRadius: 'md' })}
61-
styles={{
62-
viewport: {
63-
minHeight: '400px'
64-
}
65-
}}
66-
>
67-
{children}
68-
</ScrollArea>
69-
);
70-
}
71-
return <>{children}</>;
72-
};
73-
7451
export const BaseTable = <T,>({
7552
data,
7653
columns,
@@ -408,23 +385,22 @@ export const BaseTable = <T,>({
408385

409386
// Helper function to render regular table
410387
const renderRegularTable = () => {
411-
return (
412-
<TableWrapper>
413-
<Table
414-
striped={!isMobile()}
415-
highlightOnHover
416-
withTableBorder
417-
withColumnBorders={isMobile()}
418-
stickyHeader
419-
style={{
420-
minHeight: isLoading ? 400 : "auto",
421-
width: isMobile() && compactView ? 'max-content' : '100%'
422-
}}
423-
className={sprinkles({
424-
minHeight: '400px',
425-
fontSize: isMobile() ? 'sm' : 'md'
426-
})}
427-
>
388+
const tableContent = (
389+
<Table
390+
striped={!isMobile()}
391+
highlightOnHover
392+
withTableBorder
393+
withColumnBorders={isMobile()}
394+
stickyHeader
395+
style={{
396+
minHeight: isLoading ? 400 : "auto",
397+
width: isMobile() && compactView ? 'max-content' : '100%'
398+
}}
399+
className={sprinkles({
400+
minHeight: '400px',
401+
fontSize: isMobile() ? 'sm' : 'md'
402+
})}
403+
>
428404
{renderTableHeader()}
429405

430406
<Table.Tbody>
@@ -491,8 +467,27 @@ export const BaseTable = <T,>({
491467
}))}
492468
</Table.Tbody>
493469
</Table>
494-
</TableWrapper>
495470
);
471+
472+
// Wrap in ScrollArea for mobile devices
473+
if (isMobile()) {
474+
return (
475+
<ScrollArea
476+
type="auto"
477+
scrollbarSize={8}
478+
className={sprinkles({ borderGray3: true, borderRadius: 'md' })}
479+
styles={{
480+
viewport: {
481+
minHeight: '400px'
482+
}
483+
}}
484+
>
485+
{tableContent}
486+
</ScrollArea>
487+
);
488+
}
489+
490+
return tableContent;
496491
};
497492

498493
// Helper function to render pagination info

0 commit comments

Comments
 (0)