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

104
Views
how do l hold a lot of same information from api in react

I have a problem with react, if I fetch the same information from an API and that information is repeated, I have to create a lot of variables to hold every single one of the information.

So I repeat like const img1 and const img2 and three to hold all that l want from the same thing l just repeat it. How can l do it better?

setDisplayName(response.data.feed["0"].display.displayName);

setIngSteps(response.data.feed["0"].content.preparationSteps);

setImg(response.data.feed["0"].display.images["0"]);

setDisplayName2(response.data.feed["1"].display.displayName)

setIngSteps2(response.data.feed["1"].content.preparationSteps);

setImg2(response.data.feed["1"].display.images["0"]);

setDisplayName3(response.data.feed["1"].display.displayName)

setIngSteps3(response.data.feed["1"].content.preparationSteps);

setImg3(response.data.feed["1"].display.images["0"]);

Is there another simpler way ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There's no rule that says a state value needs to be a single value. Any object can be stored in state.

So just store the object in state:

setData(response.data);

Then you can retrieve the values from that state object as needed.

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!