• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

155
Vistas
How to get name attribute of a react-select using event.target.name
import Select from 'react-select';

const Home = () => {

    const animals = [
        { label: 'cat', value: 'cat' },
        { label: 'dog', value: 'dog' },
        { label: 'lion', value: 'lion' },
        { label: 'eagle', value: 'eagle' },
    ]
}

return (

<>
 
 <Select 
         name="animals" 
         options={animals} 
         strong text**isMulti 
         onChange={(e) => console.log(e.target.name)} 
  />

</>

)

**in console when i select some item it will give me this error

cannot read property of undefined (reading 'name') at onChange

enter image description here

almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Because it will return an array of object(s) {label: '', value: ''} rather than an event object.

 <Select 
    name="animals" 
    options={animals} 
    isMulti 
    onChange={(value, actionMeta) => console.log(actionMeta.name)} 
 />
almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda