I have this data structure:
const data = [
{
title: 'title',
description: 'description'
images: [
{ mainImg: 'url' },
{ img1: 'url' },
{ img2: 'url' },
{ img3: 'url' },
],
},
...
]
My question is, how can I render only the mainImg separated from the others? And how can I render the other images without the mainImg.
What I've tied so far is to map through the images like this: (I did mapped through data before)
{data.images.map((img, index) => (
<img
key={`image${index}`}
src={img.mainImg}
className={styles.mainImg}
/>
))
}
This worked, but the issue is that I map through all the images and when I open the consoles, all the images are rendered but they are not visible because they don't have the src tag. (I think).
Simply trying to use data.images.mainImg as the src value doesn't render anything, and also does not throw any errors.
Also, I have an issue trying to render all the other images except the mainImg. This is what I've tried but I get lost and I don't know what the src value should be.
{data.images
.filter((img) => img.mainImg != project.images.mainImg)
.map((img, index) => (
<img src={img} />
))
}