Skip to content

Commit f4eeb2e

Browse files
Azir-11honghuangdc
authored andcommitted
fix(hooks): prevent program freezing when pagesize returns 0 (#545)
1 parent 793b16e commit f4eeb2e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/hooks/common/table.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,20 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
4040
transformer: res => {
4141
const { records = [], current = 1, size = 10, total = 0 } = res.data || {};
4242

43+
// Ensure that the size is greater than 0, If it is less than 0, it will cause paging calculation errors.
44+
const pageSize = size <= 0 ? 10 : size;
45+
4346
const recordsWithIndex = records.map((item, index) => {
4447
return {
4548
...item,
46-
index: (current - 1) * size + index + 1
49+
index: (current - 1) * pageSize + index + 1
4750
};
4851
});
4952

5053
return {
5154
data: recordsWithIndex,
5255
pageNum: current,
53-
pageSize: size,
56+
pageSize,
5457
total
5558
};
5659
},

0 commit comments

Comments
 (0)