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

199
Vistas
problem/weird bug with my code ( can't access property "map", Object.values(...)[0] is undefined)

I have a problem with my react code. It keeps saying that I can't access property "map", because Object.values(...)[0] is undefined. this will usually mean that whatever is inside my object values is unreachable, or doesnt exit. However it does. I just need to remove pic and grades from persons for it to work. Sometimes i need refresh the page a few times and it will work as well.

anyone know why this might be happening.


import axios from 'axios'
import { useState, useEffect } from 'react'
import './App.css'

function App() {
  const [students, setStudents] = useState([])

  const hook = () => {
    axios
      .get('https://api.hatchways.io/assessment/students')
      .then(response => {
        console.log("promise filled")
        setStudents(response.data)
      })
  }

  useEffect(hook, ([]))
  console.log((Object.values(students)[0]))
  const Person = ({ firstname, lastname, email, company, skill, grades
    , pic }) => {

    const temp = grades.reduce((a, b) => Number(a) + Number(b), 0)
    const average = temp / grades.length

    return <>
      <div>
        <img src={pic} />
        <h1>{firstname}  {lastname}</h1>
        <p>Email: {email}</p>
        <p>Company: {company}</p>
        <p>Skill: {skill}</p>
        <p>Average: {average}%</p>



      </div>
    </>

  }


  return (
    <div class = "wrapper">
      {((Object.values(students))[0]).map(person =>
        <Person

          firstname={person.firstName}
          lastname={person.lastName}
          email={person.email}
          company={person.company}
          skill={person.skill}
          pic={person.pic}
          grades={person.grades}
          key={person.id}


        />

      )}






    </div>

  )




}


export default App;

about 4 years ago · Juan Pablo Isaza
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