Skip to content

Commit 453aa83

Browse files
committed
Check for nullness of 'data' in a separate component
This ensures we can use hooks after the check in the main component
1 parent 260bf0e commit 453aa83

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

extensions/ql-vscode/src/view/compare-performance/ComparePerformance.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,23 @@ export function ComparePerformance(_: Record<string, never>) {
357357
[setData],
358358
);
359359

360+
if (!data) {
361+
return <div>Loading performance comparison...</div>;
362+
}
363+
364+
return <ComparePerformanceWithData data={data} />;
365+
}
366+
367+
function ComparePerformanceWithData(props: {
368+
data: SetPerformanceComparisonQueries;
369+
}) {
370+
const { data } = props;
371+
360372
const datasets = useMemo(
361-
() =>
362-
data == null
363-
? undefined
364-
: {
365-
from: new ComparisonDataset(data.from),
366-
to: new ComparisonDataset(data.to),
367-
},
373+
() => ({
374+
from: new ComparisonDataset(data.from),
375+
to: new ComparisonDataset(data.to),
376+
}),
368377
[data],
369378
);
370379

@@ -378,10 +387,6 @@ export function ComparePerformance(_: Record<string, never>) {
378387

379388
const [metric, setMetric] = useState<Metric>(metrics.tuples);
380389

381-
if (!datasets) {
382-
return <div>Loading performance comparison...</div>;
383-
}
384-
385390
const { from, to } = datasets;
386391

387392
const nameSet = new Set(from.data.names);

0 commit comments

Comments
 (0)