您可以使用suggestionComponent prop 根据您的需要自定义建议。
提示说明 - 建议组件仍处于测试版。您必须将您的库更新到版本 6。
See Working copy of your code here (with version 6)
代码 sn-p
function SuggestionComponent({ item, query }) {
return (
<span id={item.id}>
{item.name} - {item.id}
</span>
);
}
const TagAutocomplete = ({ input: { value, onChange } }) => {
const suggestions = [
{ id: 1, name: "Apples" },
{ id: 2, name: "Pears" },
{ id: 3, name: "Bananas" },
{ id: 4, name: "Mangos" },
{ id: 5, name: "Lemons" },
{ id: 6, name: "Apricots" }
];
const newValue = !value ? [] : value;
const handleDelete = i => {
const tags = [...newValue];
tags.splice(i, 1);
onChange(tags);
};
const handleAdd = e => {
console.log("e", e);
onChange([...newValue, e]);
};
return (
<ReactTags
suggestionComponent={SuggestionComponent}
tags={newValue}
suggestions={suggestions}
handleDelete={handleDelete}
handleAddition={handleAdd}
/>
);
};