[英]I want to select value from react select
const [brand_id, setBrandId] = useState([])
const handleBrand = (e) => {
setBrandId(e.target.value);
console.log('hii')
}
below is react select in a component下面是组件中的 react select
<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')
无法读取未定义的属性(读取“值”)
Most of the react select library return the value object in onChange so, Your handler function should be look like:大多数反应 select 库在 onChange 中返回值 object 所以,您的处理程序 function 应该如下所示:
const handleBrand=(brand)=>{
setBrandId(brand.id);
console.log({brand});
}
and in jsx在 jsx 中
handleChange={handleBrand}
Check out the react-select props docs to learn more about Select props查看 react-select 道具文档以了解有关 Select 道具的更多信息
https://react-select.com/props#select-props https://react-select.com/props#select-props
search onChange method to explore.搜索 onChange 方法进行探索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.