Browse Source

fix: [Tree] Fix the problem of re-rendering every time the tree is rendered under virtualization (#1729)

YyumeiZhang 2 years ago
parent
commit
3afa4e9392
1 changed files with 5 additions and 4 deletions
  1. 5 4
      packages/semi-ui/tree/index.tsx

+ 5 - 4
packages/semi-ui/tree/index.tsx

@@ -664,6 +664,10 @@ class Tree extends BaseComponent<TreeProps, TreeState> {
         return item.key;
     };
 
+    option = ({ index, style, data }: OptionProps) => (
+        this.renderTreeNode(data[index], index, style)
+    );
+
     renderNodeList() {
         const { flattenNodes, cachedFlattenNodes, motionKeys, motionType } = this.state;
         const { virtualize, motion } = this.props;
@@ -683,9 +687,6 @@ class Tree extends BaseComponent<TreeProps, TreeState> {
                 />
             );
         }
-        const option = ({ index, style, data }: OptionProps) => (
-            this.renderTreeNode(data[index], index, style)
-        );
 
         return (
             <AutoSizer defaultHeight={virtualize.height} defaultWidth={virtualize.width}>
@@ -701,7 +702,7 @@ class Tree extends BaseComponent<TreeProps, TreeState> {
                         className={`${prefixcls}-virtual-list`}
                         style={{ direction }}
                     >
-                        {option}
+                        {this.option}
                     </VirtualList>
                 )}
             </AutoSizer>