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

236
Vistas
Getting the element that was clicked in functional component in React

I'm new to React and can't get the clicked element.

"this" in functional component doesn't work

function Test(data) {

    function getElement() {

    }
    return (
        <div>
            {data.map((option: any, index: any) => (
            <Text
                key={index}
                onClick={() => getElement()}
              >
                {option}
              </Text>
             ))}
         </div>
    )
}

there are several elements in the data that I want to switch one by one, changing the class 'active', but it is not possible to get the element that was clicked

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Be sure to pass the event to your click handler:

function Test(data) {
    const handleClick = e => {
        const el = e.target
        console.log(el)
    }

    return (
        <div>
            {data.map((option: any, index: any) => (
                <Text
                    key={index}
                    onClick={handleClick}
                >
                    {option}
                </Text>
            ))}
        </div>
    )
}
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