Skip to content

Commit ecfa0ff

Browse files
Convert dataRows to a useMemo
1 parent 3957d35 commit ecfa0ff

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

extensions/ql-vscode/src/view/results/raw-results-table.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import { useCallback, useEffect, useRef, useState } from "react";
2+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
33
import {
44
className,
55
emptyQueryResultsMessage,
@@ -116,17 +116,20 @@ export function RawTable({
116116
};
117117
}, [handleNavigationEvent]);
118118

119-
let dataRows = resultSet.rows;
119+
const [dataRows, numTruncatedResults] = useMemo(() => {
120+
if (resultSet.rows.length <= RAW_RESULTS_LIMIT) {
121+
return [resultSet.rows, 0];
122+
}
123+
return [
124+
resultSet.rows.slice(0, RAW_RESULTS_LIMIT),
125+
resultSet.rows.length - RAW_RESULTS_LIMIT,
126+
];
127+
}, [resultSet]);
128+
120129
if (dataRows.length === 0) {
121130
return emptyQueryResultsMessage();
122131
}
123132

124-
let numTruncatedResults = 0;
125-
if (dataRows.length > RAW_RESULTS_LIMIT) {
126-
numTruncatedResults = dataRows.length - RAW_RESULTS_LIMIT;
127-
dataRows = dataRows.slice(0, RAW_RESULTS_LIMIT);
128-
}
129-
130133
const tableRows = dataRows.map((row: ResultRow, rowIndex: number) => (
131134
<RawTableRow
132135
key={rowIndex}

0 commit comments

Comments
 (0)