Antd TreeNode上的重新租赁太多

发布于 2025-01-27 11:03:01 字数 962 浏览 2 评论 0原文

我在我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉风有信 2025-02-03 11:03:01

有一种方法可以减少titlerender调用的数量。为此,您可以设置Motion虚拟 props props to false。可能是这样的:

<Tree
    virtual={false}
    motion={false}
    titleRender={titleRender}
    treeData={treeData}
/>

我做了简单 demo app 为此。我们可以看到大约400-500 titlerender在我们展开/折叠的顶部节点时调用。如果我们设置Motion虚拟 props profs to false,我们将获得约10-30 titlerender呼叫。

此外,还有 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 set motion and virtual props to false. It could be something like that:

<Tree
    virtual={false}
    motion={false}
    titleRender={titleRender}
    treeData={treeData}
/>

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 set motion and virtual props to false, we get about 10-30 titleRender calls.

Also, there is an issue in Ant Design GitHub repository about titleRender performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文