I am getting the following error:
react Each child in a list should have a unique "key" prop.
Parent component:
{data.products
.slice(4, 9)
.map(
({
onSale,
slug,
imageMain,
productHeadline,
outOfStock,
onSalePrice,
}) => (
<>
{onSale === true ? (
<HomeFeatured
slug={slug}
imageMain={imageMain}
productHeadline={productHeadline}
onSalePrice={onSalePrice}
outOfStock={outOfStock}
/>
) : (
<></>
)}
</>
)
)}
Child component:
function HomeFeatured({
slug,
imageMain,
productHeadline,
onSalePrice,
outOfStock,
}) {
return (
<div key={slug} className="xl:w-72 lg:w-48 xs:w-60 transition ease-in-out delay-110 hover:-translate-y-1 hover:scale-105 duration-200 ">
<div className="rounded overflow-hidden shadow-lg">
</div>
</div>
);
}
I have added a key to the parent div but I am still getting the error in the console. I even added a key to the parent component and still would not work. I have done very similar array mapping in other parts of my application but this part has been componentised. Is this the reason why it may not be rendering possibly??
I feel like I have added the key and React is just being picky but I still would like to solve this issue.