Skip to content

Instantly share code, notes, and snippets.

@MeliAlbu
Created September 7, 2020 23:33
Show Gist options
  • Save MeliAlbu/6cf6b5eb26895735d14a50a7c68d1e49 to your computer and use it in GitHub Desktop.
Save MeliAlbu/6cf6b5eb26895735d14a50a7c68d1e49 to your computer and use it in GitHub Desktop.
list
import React, { useState, useEffect } from "react";
import Item from "../Navbar/Item";
export default function List() {
const [items, setItems] = useState({});
useEffect(() => {
fetchData();
}, []);
async function fetchData() {
const getData = await fetch(
"https://api.mercadolibre.com/sites/MLA/search?q=zapatillas"
);
const getJson = await getData.json();
setItems(getJson.results);
console.log(getJson);
console.log("holasa,", getJson.results);
}
useEffect(() => {
fetchData();
}, []);
return (
<>
{items.map((item, key) => {
return <Item data={item} key={item.id ? item.id : key} />;
})}
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment