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

88
Visualizações
Fetching data inside of mapped components

Not sure how best to phrase this question, other than asking for a clean way to do it.

I have an array of objects each containing a name and a URL, i'm mapping over each item so i can fetch data from the URL and display it, however there are hundreds of items, meaning hundreds of fetch requests.

This is what i have:

Index.js:

const fruits = [
  { name: "apple", url: "http://foo" },
  { name: "banana", url: "http://bar" },
];

const App = () => {
  return fruits.map((fruit) => {
    <FruitContainer fruit={fruit} />;
  });
};

FruitContainer.js

const FruitContainer = (fruit) => {
  const [fruitData, setFruitData] = useState({});

  const getFruitData = async () => {
    const data = await fetch(fruit.url);
    let json = await data.json();
    setFruitData(json);
  };

  useEffect(() => {
    getFruitData();
  }, []);

  return (
    <>
      <Text>{fruitData.name}</Text>
      <Text>{fruitData.color}</Text>
    </>
  );
};

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

0

instead of mapping in parent container send a array to child component and then create a use effect and inside useeffect pass a if condition pass a condition and then do rest of your requests otherwise it will make it slow use dynamic import

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