【发布时间】:2020-10-28 22:17:06
【问题描述】:
我在 AsyncSelect 周围使用 react-hook-forms Controller api,从 react-select 加载选项,因为用户从外部 API 键入。一切正常,除了返回值作为字符串 "[object Object]" 而不是对象的 fullName 属性返回。
我的组件:
<Controller
control={control}
name="businessCategory"
as={
<AsyncSelect
className="react-select-container"
loadOptions={v => handleAutocompleteLookup(v)}
onChange={handleCategoryInputChange}
getOptionLabel={option => option.name}
getOptionValue={option => option.fullName}
/>
}
/>
我的 handleChange 函数。 SetValue 来自 react-hook-form:
const handleCategoryInputChange = newValue => {
return setValue('businessCategory', newValue, true);
};
我的任何数据都是具有以下形状的对象数组:
{
fullName: "DJ service"
id: "gcid:dj"
name: "DJ service"
publisher: "GMB"
}
如有任何线索,我们将不胜感激,谢谢!
【问题讨论】:
标签: reactjs react-select react-hook-form