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

268
Visualizações
How to combine the received data in a state?

When I execute an API request, I get a lot of objects that are not connected by a common array. I'm trying to combine them into one state, but only one value is stored. How can I store all the received objects in the general array of my state? Everything would be fine, but I need the array to be stored in the state, in which all objects from the API will lie, in order to transfer this array to Redax

 const [planets, setPlanets] = useState([]);

useEffect(() => {
 (async () => {
  const users = await axios(world);
  const worldData = users.data;
  setPlanets(worldData);
 })();
 }, [nextTeam, world]);

and i take get data

enter image description here

I am trying to transfer all these objects to state planets, but objects are transferred there individually. Not creating an array.

This is a screenshot of console.log(planets)

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use Object.keys

let planets = {
  tatooine:{
    population: "1,3M", type: "desert"
  },
  coruscant:{
    population: "130B", type: "city"
  },
}
let array = []
Object.keys(planets).forEach(planet => array.push({
    name: planet,
    ...planets[planet]
}))
console.log(array)

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