Skip to content

Commit

Permalink
Check for nullness of 'data' in a separate component
Browse files Browse the repository at this point in the history
This ensures we can use hooks after the check in the main component
  • Loading branch information
asgerf committed Nov 14, 2024
1 parent d66b540 commit 38976e9
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,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],
);

Expand All @@ -365,10 +374,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);
Expand Down

0 comments on commit 38976e9

Please sign in to comment.