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

0

1 Answer 1

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)} 
 />
Sign up to request clarification or add additional context in comments.

3 Comments

yes sir but i want to get the name sir not the value
Still not clear. Are you trying the get the list of selected options? Can you mention that in the question? @mailtester
<Select name="this value i want to get sir" /> <option value="not this value">item</option>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.