【发布时间】:2022-11-13 13:08:21
【问题描述】:
我正在使用 AntD 树,并且我有一个想要作为图标或标题传递的反应元素,因为它具有自定义样式。由于它是 IP,我无法共享太多代码,但我的问题是: 如何将反应元素(见下文,即通用名称)作为标题或图标传递并让 antD 树呈现它?
即这是我想作为道具传递给图标或标题的内容
import React from 'react';
const genericName = (props) => {
// code uses props to get some infor for Color
// cant share code due to proprietary reasons
// but it is not needed for this question
const colorHTML = getColor(Color);
return (
<div>
<div className={`colors from`}>${colorHTML}</div>
{pin}
</div>
);
};
export default genericName;
在我的控制台中,您可以看到 node.icon 是 react.element 类型。我想以此为目标,只需将道具作为标题或图标传递给 antD 树
IE。
return (
<Tree
icon={node.icon}
/>
)
在antD禁止使用children并严格允许treeData之前,我已经搜索并给出了类似的答案。我看到的所有示例都只在标题/图标中使用字符串,但由于 antD 文档非常有限,我需要知道我的用例是否可行。现在,对于我的生活,我无法理解为什么它没有填充。
先感谢您。
【问题讨论】: