I've tried everything I possibly could but for some reason, only the first index in the array ([{...}, {...}, {...}]
) is being displayed on the browser - the other two indices are being ignored. I've searched this problem up on SO and found some similar issues people were facing but none of their solutions worked for me.
What am I doing wrong? How can I make it so that all contents in the array are being shown on the browser?
Here's my code:
import React, {useEffect, useState} from "react";
import '../../../sass/prizes/prizes.scss';
const Prizes = () => {
const [prizeData, setPrizeData] = useState([]);
useEffect(() => {
axios.get('http://localhost/api/prizes')
.then(resp => {
setPrizeData([resp]);
console.log(prizeData)
}).catch(error => {
console.log(error);
});
}, []);
return (
<div className="main">
<h1>Prizes</h1>
<ul className="cards">
<li className="cards_item">
<div className="card">
{
prizeData.map((prizes, index) => {
return(
<>
<div className="card_image"><img src={prizes.data[index].image_url} className="giftCards"/></div>
<div className="card_content">
<h2 className="card_title">{prizes.data[index].prizeName}</h2>
</div>
</>
);
})
}
</div>
</li>
</ul>
</div>
);
};
export default Prizes;