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

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

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