diff --git a/src/components/Table/Table.tsx b/src/components/Table/Table.tsx index 698587d4a..4a12ea295 100644 --- a/src/components/Table/Table.tsx +++ b/src/components/Table/Table.tsx @@ -42,7 +42,6 @@ const Table = >({ sorting, rowsConfig, columnsConfig, - pagination, dataTestPrefixId, }); diff --git a/src/components/Table/hooks/useTable.tsx b/src/components/Table/hooks/useTable.tsx index f1fff3d82..ade2c7a63 100644 --- a/src/components/Table/hooks/useTable.tsx +++ b/src/components/Table/hooks/useTable.tsx @@ -8,7 +8,7 @@ import { } from '@tanstack/react-table'; import useTheme from 'hooks/useTheme'; import { concat } from 'lodash-es'; -import React from 'react'; +import React, { useMemo } from 'react'; import type { Theme } from 'theme'; import { CheckBox } from 'components/Controls'; @@ -152,7 +152,6 @@ const useTable = ({ sorting, rowsConfig, columnsConfig, - pagination, dataTestPrefixId, ...rest }): ReturnValue => { @@ -164,6 +163,8 @@ const useTable = ({ const hasRowDetails = data.some((row) => row.details) && Boolean(expanded); + const tableData = useMemo(() => data.map((data) => data.cells), [data]); + const hasCheckboxes = Boolean(rowSelection && isTableInteractive); const tColumns = getColumns(columns, hasCheckboxes, hasRowDetails, theme, dataTestPrefixId); @@ -177,13 +178,6 @@ const useTable = ({ }; }, [columnsConfig, expanded, isTableInteractive, rowSelection, sorting]); - /** Since tanstack's useTable doesn't detect array object mutations, we need to manually create new data array (new ref) to trigger a re-render */ - const [tableData, setTableData] = React.useState(data.map((data) => data.cells)); - - React.useEffect(() => { - setTableData(data.map((data) => data.cells)); - }, [sorting?.sortingColumn, pagination?.page, pagination?.showItems]); - const table = useReactTable({ /** Basic Functionality */ data: tableData,