Skip to content

Commit 3b9879d

Browse files
committed
fix: Infinite loop in GenericList
1 parent 4368dfe commit 3b9879d

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/shared/components/GenericList/GenericList.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,22 @@ export const GenericList = ({
124124
const [searchQuery, setSearchQuery] = useState('');
125125

126126
useEffect(() => {
127-
if (pagination) {
128-
// move back when the last item from the last page is deleted
129-
const pagesCount = Math.ceil(entries.length / pagination.itemsPerPage);
130-
if (currentPage > pagesCount && pagesCount > 0) {
131-
setCurrentPage(pagesCount);
127+
if (entries.length > 0) {
128+
if (pagination) {
129+
// move back when the last item from the last page is deleted
130+
const pagesCount = Math.ceil(entries.length / pagination.itemsPerPage);
131+
if (currentPage > pagesCount && pagesCount > 0) {
132+
setCurrentPage(pagesCount);
133+
}
132134
}
135+
setFilteredEntries(
136+
filterEntries(
137+
sorting(sort, entries),
138+
searchQuery,
139+
searchSettings?.textSearchProperties,
140+
),
141+
);
133142
}
134-
setFilteredEntries(
135-
filterEntries(
136-
sorting(sort, entries),
137-
searchQuery,
138-
searchSettings?.textSearchProperties,
139-
),
140-
);
141143
// eslint-disable-next-line react-hooks/exhaustive-deps
142144
}, [
143145
searchQuery,

0 commit comments

Comments
 (0)