The Arrays.map is only working for the first object of the array .
This the is the main Function :-
function App(){
return (
<div>
<NavBar />
{
data.map((prop) => {
return <Card img = {prop.img} title = {prop.title} />
})
};
</div>
);
}
ReactDOM.render(App() , document.getElementById('root'));
The Card that is supposed to take different values from map function :-
export default function Card({img , title}){
return (
<div id = "card">
<div id = "card-image">
<img src = {img} alt = "capy1"></img>
</div>
<div id = "card-info">
<span id = "card-title"><h3>{title}</h3></span>
<span>
<h4>Weight : </h4>
<p>
</p>
</span>
<span>
<h4>
Height :
</h4>
<p>
</p>
</span>
<span>
<h4>
Description :
</h4>
<p>
</p>
</span>
</div>
</div>
);
}
The Data that is being passed is :-
const data = [
{
title: "GOD OF CAPYS",
img: "./resources/capy1.jpg"
},
{
title: "Black CAPYS",
img: "./resources/black_capy.jpg"
}
];
export default data;
The Output is just the first card . The 2nd card is not rendering maybe because its now getting the data from the array.
3
Answers
I recommend that you get adequate training.
Question answer;
return is just function redirection. It cannot run a loop.
try with this code Check this
However i recommend using index as key
works fine for me in both ways!!