Reputation: 37
I'm fetching a Fortnite API to see some details. I create an array that i will set to api data when i call setItemsArray method. But is not working!!!
useEffect(() => {
fetchItems()
}, [])
const [itemsArray, setItemsArray] = useState([])
const fetchItems = async () => {
const data = await fetch('https://fortnite-api.com/v1/map')
const items = await data.json()
setItemsArray(items.data.pois)
console.log(items.data.pois)
}
return (
<div>
<h1>Shop</h1>
<div>
{itemsArray.map(el => {
<h1>{el}</h1>
})}
</div>
</div>
Upvotes: 0
Views: 597
Reputation: 361
It's not showing because you are not returning the data. You can fix this using two options:
<div>
{itemsArray.map(el => {
return <h1>{el}</h1>
})}
</div>
2. ```
<div>
{itemsArray.map(el => (
<h1>{el}</h1>
))}
</div>
Upvotes: 3