I had a javascript array that was rendering components using array.map
. I switched this array to an es6 Map
in order to be able to use key-value pairs to find items more easily, and switched from a .map
to a forEach
over the Map. Inside the forEach
I call a render method that returns a React component, but it isn't being rendered. How do I render a component inside the forEach
?
<div className='gallery__items'>
{resultsByGuid.forEach((result, index) => {
key++;
this.renderGalleryItem(result, key);
})}
</div>
Here is the renderGalleryItem method:
renderGalleryItem = (item, index) => {
const { gridItemSelected, itemThumbnailRequested } = this.props;
return (
<GalleryItem
key={index}
item={item}
onClick={gridItemSelected}
fetchThumbnailFunc={itemThumbnailRequested}
/>
);
};
I understand that forEach doesn't return anything but does that mean I can't render inside it?