TablePanel: avoid toArray for memoizedData (#23744)

This commit is contained in:
Ryan McKinley
2020-04-21 14:42:27 -07:00
committed by GitHub
parent 1ca3ce59e2
commit 32d7a4d33a

View File

@@ -72,7 +72,18 @@ export const Table: FC<Props> = memo((props: Props) => {
// React table data array. This data acts just like a dummy array to let react-table know how many rows exist
// The cells use the field to look up values
const memoizedData = useMemo(() => {
return data.fields.length > 0 ? data.fields[0].values.toArray() : [];
if (!data.fields.length) {
return [];
}
// Check if an array buffer already exists
const buffer = (data.fields[0].values as any).buffer;
if (Array.isArray(buffer) && buffer.length === data.length) {
return buffer;
}
// For arrow tables, the `toArray` implementation is expensive and akward *especially* for timestamps
return Array(data.length).fill(0);
}, [data]);
// React-table column definitions