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

87
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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