function App() { return (
<StrictMode>
{data.map(creatcard) }
</StrictMode>
)
}
function creatcard(characters){
return(
<Card
id={characters._id}
name={characters.name}
about={characters.about}
img={characters.img}
></Card>
)}
here is my card component
function Card(pops){ return (
<div className="cards" key={pops.id}>
<div className="subhead">
<h1 >{pops.name}</h1>
</div>
<p>{abt.substring(0,200)}
<br></br> <Link to={`/${pops.name}`}>Read more...</Link></p>
<img id="dp" src={pops.img}></img>
</div>
)}
i don’t know how to solve this problem . i’ve already set key for each card in my card component
2
Answers
The key should be in the direct Component render of a map function. And your key must not have duplicates. If your IDs might have some duplicates, you can easily concat with an index to solve the warning.
The
key
prop that react is asking for should be applied as a prop on your<Card/>
component usage and not inside theCard
component. Here’s what I mean;React uses the
key
prop in list rendering to identify each list items uniquely. React needs this key to efficiently update the UI when items are added, updated or removed from the list. Hope this helps.