Skip to content

Commit

Permalink
use array concatenation instead of push in useFlattenRecords hook (#984)
Browse files Browse the repository at this point in the history
* use array concatenation instead of push in useFlattenRecords hook

* use array concatenation instead of push in useFlattenRecords hook

* add change description
  • Loading branch information
vlats05 authored May 9, 2023
1 parent 037d857 commit 38a9e02
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/hooks/useFlattenRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ export default function useFlattenRecords<T>(
) {
const arr: { record: T; indent: number; index: number }[] = React.useMemo(() => {
if (expandedKeys?.size) {
const temp: { record: T; indent: number; index: number }[] = [];
let temp: { record: T; indent: number; index: number }[] = [];

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

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

return temp;
Expand Down

1 comment on commit 38a9e02

@vercel
Copy link

@vercel vercel bot commented on 38a9e02 May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

table – ./

table-git-master-react-component.vercel.app
table-react-component.vercel.app

Please sign in to comment.