Gabriel Borges
Gabriel Borges

Reputation: 37

Why is not displaying my list from my api on my react app?

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

Answers (1)

Asit Prakash
Asit Prakash

Reputation: 361

It's not showing because you are not returning the data. You can fix this using two options:

  1. 
     <div>
           {itemsArray.map(el => {
             return <h1>{el}</h1>
           })}
         </div>
    
    
2. ```

    <div>
          {itemsArray.map(el => (
            <h1>{el}</h1>
          ))}
        </div>

Upvotes: 3

Related Questions