Check for nullness of 'data' in a separate component

This ensures we can use hooks after the check in the main component
This commit is contained in:
Asger F
2024-11-14 15:29:00 +01:00
parent 260bf0e8d1
commit 453aa833f2

View File

@@ -357,14 +357,23 @@ export function ComparePerformance(_: Record<string, never>) {
[setData],
);
if (!data) {
return <div>Loading performance comparison...</div>;
}
return <ComparePerformanceWithData data={data} />;
}
function ComparePerformanceWithData(props: {
data: SetPerformanceComparisonQueries;
}) {
const { data } = props;
const datasets = useMemo(
() =>
data == null
? undefined
: {
from: new ComparisonDataset(data.from),
to: new ComparisonDataset(data.to),
},
() => ({
from: new ComparisonDataset(data.from),
to: new ComparisonDataset(data.to),
}),
[data],
);
@@ -378,10 +387,6 @@ export function ComparePerformance(_: Record<string, never>) {
const [metric, setMetric] = useState<Metric>(metrics.tuples);
if (!datasets) {
return <div>Loading performance comparison...</div>;
}
const { from, to } = datasets;
const nameSet = new Set(from.data.names);