Skip to content

Commit

Permalink
Abandoning useEffect as it was unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-cedrone-cengage committed Jan 24, 2025
1 parent a3758bb commit ef766c8
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions packages/react-magma-dom/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ export const TableContext = React.createContext<TableContextInterface>({

export const TableContainer = styled.div<{
isInverse?: boolean;
minWidth: number;
tableOverFlow?: string;
}>`
overflow: ${props => props.tableOverFlow};
@media screen and (max-width: ${props => props.minWidth}px) {
overflow: auto;
}
&:focus {
outline: none;
}
Expand Down Expand Up @@ -167,27 +170,27 @@ export const Table = React.forwardRef<HTMLTableElement, TableProps>(

const tableWrapper = `table-wrapper-${testId}`;

const [tableOverFlow, setTableOverFlow] = React.useState<string>('visible');
// const [tableOverFlow, setTableOverFlow] = React.useState<string>('visible');

const [windowWidth, setWindowWidth] = React.useState(window.innerWidth);
// const [windowWidth, setWindowWidth] = React.useState(window.innerWidth);

React.useEffect(() => {
function handleResize() {
setWindowWidth(window.innerWidth);
if (window.innerWidth < minWidth && minWidth) {
setTableOverFlow('auto');
}
// React.useEffect(() => {
// function handleResize() {
// setWindowWidth(window.innerWidth);
// if (window.innerWidth < minWidth && minWidth) {
// setTableOverFlow('auto');
// }

if (window.innerWidth > minWidth) {
setTableOverFlow('visible');
}
}
// if (window.innerWidth > minWidth) {
// setTableOverFlow('visible');
// }
// }

window.addEventListener('resize', handleResize);
handleResize();
// window.addEventListener('resize', handleResize);
// handleResize();

return () => window.removeEventListener('resize', handleResize);
}, [windowWidth]);
// return () => window.removeEventListener('resize', handleResize);
// }, [windowWidth]);

return (
<TableContext.Provider
Expand All @@ -206,7 +209,7 @@ export const Table = React.forwardRef<HTMLTableElement, TableProps>(
<TableContainer
data-testid={tableWrapper}
isInverse={isInverse}
tableOverFlow={tableOverFlow ? tableOverFlow : null}
minWidth={minWidth}
theme={theme}
tabIndex={0}
>
Expand Down

0 comments on commit ef766c8

Please sign in to comment.