TableView: Fix re-render loop

This commit is contained in:
arttu
2024-05-28 22:23:57 +03:00
parent 438392164a
commit f8410fe7f4
@@ -103,9 +103,15 @@ export const TableView = <T extends MRT_RowData>({
const sortingToUrl = `sorting=${JSON.stringify(sorting)}`
const paginationToUrl = `pagination=${JSON.stringify(pagination)}`
setTableUrl(`${location.pathname}?&${columnFilterToUrl}&${sortingToUrl}&${paginationToUrl}`)
setIdList(table.getPrePaginationRowModel().rows.map(row => row.original[idFieldName] as string))
}, [columnFilters, sorting, pagination, location.pathname, selectorFn, setIdList, table, idFieldName, setTableUrl])
useEffect(() => {
setIdList(table.getPrePaginationRowModel().rows.map(row => row.original[idFieldName] as string))
// Don't put setIdList in the dependency array: it will cause re-render loop.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [table, columnFilters, sorting])
if (!data) return <CircularProgress />
return <MaterialReactTable table={table} />