2
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

Sanket Shah
  • 2,888
  • 1
  • 11
  • 22

1 Answers1

2

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)} 
 />
Sanket Shah
  • 2,888
  • 1
  • 11
  • 22