Skip to content

Commit

Permalink
moved null return to after hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbnr committed Jun 19, 2024
1 parent d1c3abb commit e424ba7
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions visualizations/store-map-viz/components/Region.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ const Region = ({
const { regionColors } = useProps();
const { customColors } = useCustomColors(regionColors, false);

if (!regionFeature) {
console.log("Region not found for data, will not render", location);
return null;
}


const gradientColor = getGradientColor(location.value);

const style = useMemo(() => {
Expand Down Expand Up @@ -53,18 +49,20 @@ const Region = ({
location.status,
]);



// determine the tooltip title, memoized to avoid unnecessary recalculations
const getTooltipTitle = () => {
if (location.tooltip_header === "NONE" || location.tooltip_header === "") {
return null;
}
return location.tooltip_header
? location.tooltip_header
: regionFeature.name;
: regionFeature?.name;
};
const tooltipTitle = useMemo(getTooltipTitle, [
location.tooltip_header,
regionFeature.name,
regionFeature?.name,
]);

// extracted onClick handler
Expand All @@ -74,6 +72,11 @@ const Region = ({
}
};

if (!regionFeature) {
console.log("Region not found for data, will not render", location);
return null;
}

return (
<GeoJSON
key={key + "-" + location.value + "-" + style.fillColor}
Expand Down

0 comments on commit e424ba7

Please sign in to comment.