Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

89
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!