Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
Uncaught TypeError: equipo.data is undefined using React

I have the following problem trying to traverse an array of objects and I don't know where the problem is.

import './App.css';
import React from 'react';

function App() {

  const [equipo, setEquipo] = React.useState([]);

  // Constructor
  React.useEffect(() => {
    document.title = "Magic - React";
    obtenerDatos();
  }, []);

  // Metodo que recoge info de una Api
  const obtenerDatos = async () => {
    const data = await fetch("https://api.scryfall.com/cards/search?order=set&q=e%3Augin&unique=prints");
    const info = await data.json();
    setEquipo(info);
  };

  return (
    <div className="App">
      <ul>
        {equipo.data.map((item) => (
          <li>{item.name}</li>
        ))}
      </ul>
    </div>
  );
}

export default App;

Here is the JSON Api where I search the info.

https://api.scryfall.com/cards/search?order=set&q=e%3Augin&unique=prints

I try to show the images and the text of the cards in the HTML. I am new with React. Please help and thanks.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try this:

return (
    <div className="App">
      <ul>
        {equipo?.data?.map((item) => (
          <li>{item.name}</li>
        ))}
      </ul>
    </div>
  );
about 4 years ago · Juan Pablo Isaza Relatório

0

This is your issue:

const [equipo, setEquipo] = React.useState([]);

On the first render, before the API call has returned, you're attempting to access the .data field of an empty array. Instead, you need to initialize equipo with:

const [equipo, setEquipo] = React.useState({data: []});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda