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

127
Vistas
Able to log array in console, but can't loop through it

Running into a problem. In react I'm grabbing data from a json api. Everything worked fine until I tried to display it. Except, I'm able to log it on the console.

What the console logs:

pic

<ul role="list" className="divide-y divide-gray-200 dark:divide-gray-700">
{username !== "null" && leaderlist.length > 2 && console.log(leaderlist) && leaderlist.map((leader, index) =>
       <li className="py-3 sm:py-4 text-white">
           Log 
        </li>
      )}
     <li className="py-3 sm:py-4 text-white">
         list length {leaderlist.length} 
     </li>
   </ul>

What it displays:

enter image description here

The code that sets

const [leaderlist, setleaderlist] = React.useState([]);
fetch(`${baseurl}/allusers`)
     .then(res => res.json())
     .then(data => {setleaderlist(data); console.log(data)})
     .catch(err => console.log(err));
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

username !== "null" && leaderlist.length > 2 && console.log(leaderlist) && leaderlist.map((leader, index)

console.log(leaderlist) does not have a return value and thus leaderlist.map((leader, index) ...) does not run since you're using &&. You need to remove the console.log statement or use ; instead of &&.

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