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

130
Vistas
Event.target.id returns empty string

Hello I have a problem with returning an id value (defined in the key attribute) of the image when using event.target.

function imageClicked(event) {
    console.log(event.target.key);
    setClicked(event.target.key);
    shuffle(GameData);
    if (clicked.includes(event.target.key) === false) {
      setScore(score + 1);
      setClicked([...clicked, event.target.key]);
    } else {
      setScore(0);
      setClicked([]);
    }
  }

...

 <Display onClick={imageClicked} items={GameData} />

And component fragment:

<div className="display">
      <img
        src={props.image}
        alt={props.name}
        key={props.id}
        onClick={props.onClick}
      />
      <p>{props.name}</p>
    </div>

However when I am using an alt attribute of the image the app works as intended. But I want to change it anyway as I creacted ids for all images and they are currently unused.

Thanks in advance.

Here is the link to the full app (using alt attribute) in CodeSandbox.

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