Skip to content

Commit 38a9e02

Browse files
authored
use array concatenation instead of push in useFlattenRecords hook (#984)
* use array concatenation instead of push in useFlattenRecords hook * use array concatenation instead of push in useFlattenRecords hook * add change description
1 parent 037d857 commit 38a9e02

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/hooks/useFlattenRecords.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,16 @@ export default function useFlattenRecords<T>(
6060
) {
6161
const arr: { record: T; indent: number; index: number }[] = React.useMemo(() => {
6262
if (expandedKeys?.size) {
63-
const temp: { record: T; indent: number; index: number }[] = [];
63+
let temp: { record: T; indent: number; index: number }[] = [];
6464

6565
// collect flattened record
6666
for (let i = 0; i < data?.length; i += 1) {
6767
const record = data[i];
6868

69-
temp.push(...flatRecord<T>(record, 0, childrenColumnName, expandedKeys, getRowKey, i));
69+
// using array.push or spread operator may cause "Maximum call stack size exceeded" exception if array size is big enough.
70+
temp = temp.concat(
71+
...flatRecord<T>(record, 0, childrenColumnName, expandedKeys, getRowKey, i),
72+
);
7073
}
7174

7275
return temp;

0 commit comments

Comments
 (0)