Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
Using fetch with async/await inside useEffect returns the data but the data is empty when called inside a component

I'm trying to fetch data from a mock JSON server using async/await inside useEffect and the data fetched is stored in a variable (Items) with useState. But I seem to have difficulty of using that data on a component (Content.js). the problem is when I console.log the variable to check for the fetched data inside App.js file I can see the data, but when I console.log the same variable inside the component, it returns [object Object],[object Object],[object Object],[object Object],[object Object]

function App() {
const API_URL = 'http://localhost:3500/Items';

const [Items, setItems] = useState([]);

console.log(Items)

useEffect(()=>{
const fetchItems = async () =>{
  try{
    const response = await fetch(API_URL);
    const listedItems = await response.json();

    console.log(listedItems);
    setItems(listedItems);
  }
  catch(err){ 
    console.log(err.message)
  }
}

  (async () => await fetchItems())();
}, []) 

return (
  <div>
    <Content
       Items = {Items}
     />
  
  </div>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda