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

110
Visualizações
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 Respostas
Responde à pergunta

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