|
1 | 1 | import * as React from "react"; |
2 | | -import { useCallback, useEffect, useRef, useState } from "react"; |
| 2 | +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; |
3 | 3 | import { |
4 | 4 | className, |
5 | 5 | emptyQueryResultsMessage, |
@@ -116,17 +116,20 @@ export function RawTable({ |
116 | 116 | }; |
117 | 117 | }, [handleNavigationEvent]); |
118 | 118 |
|
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 | + |
120 | 129 | if (dataRows.length === 0) { |
121 | 130 | return emptyQueryResultsMessage(); |
122 | 131 | } |
123 | 132 |
|
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 | | - |
130 | 133 | const tableRows = dataRows.map((row: ResultRow, rowIndex: number) => ( |
131 | 134 | <RawTableRow |
132 | 135 | key={rowIndex} |
|
0 commit comments