Discussion about using card parameters and custom block types in a React component.
The issue is that you're not using the card parameter from your .map() function - you're referencing data[0].card instead, which means you're always rendering the same card content for every item in your array.
Here's the fix:
{cards.map((card, index) => {
return (
<Card position={{ top: "top-[200px]", left: "left-0" }}>
<PortableText
value={card} // Use the 'card' from map, not data[0].card
components={portraitPortableTextComponents}
/>
</Card>
)
})}What was wrong:
cards.map((card, index) => {...})gives you each individualcarditem as you iterate- But inside, you were using
data[0].card, which always points to the same card in your data array - This means every iteration rendered the same content
Additional tips:
Add a key prop - React needs this for list rendering:
<Card key={index} position={{ top: "top-[200px]", left: "left-0" }}>Or better yet, if your cards have unique IDs:
key={card._id}Check your data structure - Make sure
cardsactually contains the portable text content you expect. Ifcardsis an array of objects and the portable text is nested (likecard.content), you'd use:value={card.content}Verify portable text format - Ensure each card contains properly formatted Portable Text (an array of blocks), not just a string.
If you're still having issues, check the console for any errors and verify what cards actually contains by logging it: console.log(cards).
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.