【发布时间】:2021-07-30 04:34:01
【问题描述】:
我想知道是否可以在 Select 组件内的 components 道具中同时添加动画组件和自定义组件。
不幸的是,在 react-select 文档中找不到任何内容。
对于“动画组件”,我指的是这些:https://react-select.com/home#animated-components。
“自定义组件”是:https://react-select.com/components#replaceable-components
在我的例子中,自定义组件是这个:
// Custom component
const CustomMultiValue = (
props: MultiValueProps<FilterOptions, GroupTypeBase<FilterOptions>>
) => (
<components.MultiValue {...props}>{props.data.label}</components.MultiValue>
);
// Animated components
const animatedComponents = makeAnimated();
Select 看起来像这样:
<Select
isMulti
onChange={(value) => handleChange(value)}
styles={customSelectStyles}
components={{ MultiValue: CustomMultiValue }}
theme={customSelectTheme}
closeMenuOnSelect={false}
placeholder={placeholder}
/>
我尝试了很多方法来添加动画组件,但似乎没有任何效果。 例如:
components={animatedComponents, { MultiValue: CustomMultiValue }}
components={{ MultiValue: CustomMultiValue, Control: animatedComponents }}
有人有想法吗? 谢谢!
【问题讨论】:
标签: reactjs react-select