我正在尝试使用react-select 创建一个选择元素,并为此使用Creatable 组件。
在我当前的实现中,它不会提示用户输入“创建”选项,如文档所示,它将 显示默认的“无选项”。
我也在使用redux-form库,但我不认为问题来自那里。
到目前为止,这是我的代码:
import Select from "react-select/creatable";
import React from "react";
const customFilter = (option, searchText) => {
return option.data.searchfield.toLowerCase().includes(searchText.toLowerCase());
};
export default (props) => {
const { input, options, placeholder } = props;
const renderValue = (value) => {
const val =
value === "" ? null : options.find((obj) => obj.value === input.value);
return val || "";
};
return (
<Select
value={renderValue(input.value)}
name={input.name}
onFocus={() => input.onFocus(input.value)}
onChange={(value) => input.onChange(value.value)}
onBlur={() => input.onBlur(input.value)} …Run Code Online (Sandbox Code Playgroud)