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

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

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