Skip to content

fix: initial params in useEffect #2321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions src/components/PaginatedTable/PaginatedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
PaginatedTableData,
RenderEmptyDataMessage,
RenderErrorMessage,
SortParams,
} from './types';
import {useScrollBasedChunks} from './useScrollBasedChunks';

Expand All @@ -29,7 +28,6 @@ export interface PaginatedTableProps<T, F> {
getRowClassName?: GetRowClassName<T>;
rowHeight?: number;
scrollContainerRef: React.RefObject<HTMLElement>;
initialSortParams?: SortParams;
onColumnsResize?: HandleTableColumnsResize;
renderEmptyDataMessage?: RenderEmptyDataMessage;
renderErrorMessage?: RenderErrorMessage;
Expand All @@ -50,7 +48,6 @@ export const PaginatedTable = <T, F>({
getRowClassName,
rowHeight = DEFAULT_TABLE_ROW_HEIGHT,
scrollContainerRef,
initialSortParams,
onColumnsResize,
renderErrorMessage,
renderEmptyDataMessage,
Expand All @@ -64,24 +61,6 @@ export const PaginatedTable = <T, F>({

const {sortParams, foundEntities} = tableState;

// Initialize state with props if available
React.useEffect(() => {
if (initialSortParams) {
setSortParams(initialSortParams);
}

if (initialEntitiesCount) {
setTotalEntities(initialEntitiesCount);
setFoundEntities(initialEntitiesCount);
}
}, [
setSortParams,
setTotalEntities,
setFoundEntities,
initialSortParams,
initialEntitiesCount,
]);

const tableRef = React.useRef<HTMLDivElement>(null);

const activeChunks = useScrollBasedChunks({
Expand Down Expand Up @@ -120,7 +99,7 @@ export const PaginatedTable = <T, F>({
[onDataFetched, setFoundEntities, setIsInitialLoad, setTotalEntities],
);

// Reset table on filters change
// Reset table on initialization and filters change
React.useLayoutEffect(() => {
const defaultTotal = initialEntitiesCount || 0;
const defaultFound = initialEntitiesCount || 1;
Expand Down
Loading