Antd TreeNode上的重新租赁太多
我在我的React应用程序中使用了ANTD树组件。 在某个时候,我需要具有自定义标题,因此我通过将自定义组件传递给ANTD树组件上可用的“ Titlerender”道具来添加此功能。
现在问题是当我打开树(任何级别)时,我对Treenode组件上的重新渲染感到疯狂。=
打开树并检查日志在这里
这是自然行为吗?
import { Tree } from "antd";
import "antd/dist/antd.css";
const treeData = [
{
title: "parent 1",
key: "0-0",
children: [
{
title: "parent 1-0",
key: "0-0-0",
children: [
{
title: "leaf",
key: "0-0-0-0"
}
]
}
]
}
];
const Title = (props) => {
console.log("render");
return <h5>{props.title}</h5>;
};
export default () => (
<Tree
treeData={treeData}
titleRender={(nodeData) => {
return <Title title={nodeData.title} />;
}}
/>
);
I'm using of Antd tree component in my react application.
at some point I needed to have custom titles so I added this feature by passing a custom component to "titleRender" prop available on Antd tree component.
Now the issues is when I open the tree (At any level) I get a crazy about of re-render on the treeNode component.=
Open the tree and check the logs here
Is this a natural behavior?
import { Tree } from "antd";
import "antd/dist/antd.css";
const treeData = [
{
title: "parent 1",
key: "0-0",
children: [
{
title: "parent 1-0",
key: "0-0-0",
children: [
{
title: "leaf",
key: "0-0-0-0"
}
]
}
]
}
];
const Title = (props) => {
console.log("render");
return <h5>{props.title}</h5>;
};
export default () => (
<Tree
treeData={treeData}
titleRender={(nodeData) => {
return <Title title={nodeData.title} />;
}}
/>
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一种方法可以减少
titlerender
调用的数量。为此,您可以设置Motion
和虚拟
props props tofalse
。可能是这样的:我做了简单 demo app 为此。我们可以看到大约400-500
titlerender
在我们展开/折叠的顶部节点时调用。如果我们设置Motion
和虚拟
props profs tofalse
,我们将获得约10-30titlerender
呼叫。此外,还有 at ant Design github repository of aw ant Design Github repository of ab > titlerender 性能。
There is a way to decrease the number of
titleRender
calls. For this you can setmotion
andvirtual
props tofalse
. It could be something like that:I made simple demo app for that. We can see about 400-500
titleRender
calls when we expand/collapse top node of the tree. If we then setmotion
andvirtual
props tofalse
, we get about 10-30titleRender
calls.Also, there is an issue in Ant Design GitHub repository about
titleRender
performance.