Don't use flapMap for a single category in SceneryLayer

This commit is contained in:
dominik-korsa 2025-07-13 23:06:09 +02:00
parent 391be08250
commit 55312b48ae
No known key found for this signature in database
GPG Key ID: 5A24D76EE0A30974

View File

@ -13,12 +13,15 @@ export default function SceneryLayer(props) {
const objects = useMemo(() => {
if (!scenery || !isVisible) return [];
const categoryList = typeof category === 'string' ? [category] : category;
return categoryList.flatMap((category) => {
const getCategoryObjects = (category) => {
const categoryObjs = scenery.objects[category];
if (!categoryObjs) return [];
return Object.values(categoryObjs);
});
}
// flatMap is not used in the case of a single category to avoid an unnecessary array copy
if (typeof category === 'string') return getCategoryObjects(category);
return category.flatMap(getCategoryObjects);
}, [scenery, category, isVisible]);
if (!scenery || !isVisible) return null;