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

103
Visualizações
using Map for an object api

i have an object format api like this:

{ success: 1,
  result:[
     {},
     {},
     {},
     {} ]
}

how can i named a map on result parameter of this object? :/

i try 2 ways for it: 1- define api to a variable like x: const [x, setX] = useState([]); then define result of api to another varibale like: const y = x.result; and then make a map on Y .

2- define api to a variable like x: const [x, setX] = useState([]); then make it array with this method: const y = Object.entries(x); and get "result" of this array like this: const result = y[1]; and make a map on result .

but after every 2 ways i see this error in console: :(

TypeError: Cannot read properties of undefined (reading 'map')

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

0

I found that you use useEffect a little bit incorrectly. You don't need return result in useEffect function. Instead it should be passed to setState function as argument:

useEffect(async () => {
    const players = await getPlayers();
    setPlayers(players);
  }, []);

as your player data fetch operation is asynchronous, you can use conditional rendering in component:

{result ? result.map(player => <Player key={player.player_key} data={player} />) : loading...}

to shure that result won't be undefined at moment of component mounting.

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