I'm still slightly confused about map. When I comment out the map my h2 renders, what am I doing wrong? Yes I would still like to use fetch. I need to understand what I'm doing wrong before I add more depth to it.
import { useState, useEffect } from "react";
export default function SearchAPI() {
const [cocktail, setCocktail] = useState()
useEffect(() => {
fetch('https://www.thecocktaildb.com/api/json/v1/1/search.php?s=margarita')
.then(res => res.json())
.then(data => {
setCocktail(data.drinks[0])
console.log(cocktail)
})
.catch(err => {
console.log(`error ${err}`)
})
}, [])
return (
<>
<h2>here is your drink</h2>
{cocktail.map((element) => {
return <h2>{element.strDrink}</h2>
})}
</>
)
}
When I comment out the function it renders.