【发布时间】:2020-03-11 11:17:11
【问题描述】:
我在文档中找不到如何使用 optionRenderer prop 和 react-select async (Select.Async)
here is a question 已经被回答,但 renderOptions 根本没有被调用
这是我的代码的 sn-p:
renderOption = (option) => {
return (
<div>
// for example:
{option.label}: {option.value}
</div>
)
}
<Select.Async
placeholder={placeholder}
loadOptions={(inputValue) => this.asyncLoadOptions(inputValue)}
isClearable
onChange={(value, e) => {
this.onDropDownFilterChange(value, e)
}}
onMenuScrollToBottom={this.fetchDropDownNextPage}
defaultOptions={defaultOptions}
defaultValue={defaultValue}
styles={this.props.hasError ? customStyles : undefined}
optionRenderer={this.renderOption}
/>
在这里,我想保持每个下拉项目的功能和样式(例如 onMouseOver 等)我只想格式化项目在列表中的显示方式,所以这是正确的方法吗?或者除了使用 components 属性之外别无选择。
我能够使用 components 属性实现正确的格式设置,但我丢失了样式和所有鼠标事件。
【问题讨论】:
标签: javascript reactjs react-select