Reputation: 1
const [brand_id, setBrandId] = useState([])
const handleBrand = (e) => {
setBrandId(e.target.value);
console.log('hii')
}
below is react select in a component
<SearchableSelect
label={'Brand'}
important
placeholder="Select Brand"
value={brands}
options={brand}
handleChange={(e) => handleBrand(e)}
/>
The error is
Cannot read properties of undefined (reading 'value')
Upvotes: 0
Views: 60
Reputation: 61
Most of the react select library return the value object in onChange so, Your handler function should be look like:
const handleBrand=(brand)=>{
setBrandId(brand.id);
console.log({brand});
}
and in jsx
handleChange={handleBrand}
Check out the react-select props docs to learn more about Select props
https://react-select.com/props#select-props
search onChange method to explore.
Upvotes: 1