Memoize tree nodes
Reviewed By: antonk52 Differential Revision: D41838164 fbshipit-source-id: 3184f4ee607f0dd47604265fc259480403c083f0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0db0afec21
commit
fc43580134
@@ -88,7 +88,7 @@ export function Tree2({
|
|||||||
instance.uiState.hoveredNodes.set([]);
|
instance.uiState.hoveredNodes.set([]);
|
||||||
}}>
|
}}>
|
||||||
{treeNodes.map((treeNode, index) => (
|
{treeNodes.map((treeNode, index) => (
|
||||||
<TreeItemContainer
|
<MemoTreeItemContainer
|
||||||
innerRef={refs[index]}
|
innerRef={refs[index]}
|
||||||
isUsingKBToScroll={isUsingKBToScroll}
|
isUsingKBToScroll={isUsingKBToScroll}
|
||||||
key={treeNode.id}
|
key={treeNode.id}
|
||||||
@@ -107,6 +107,18 @@ export type TreeNode = UINode & {
|
|||||||
isExpanded: boolean;
|
isExpanded: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const MemoTreeItemContainer = React.memo(
|
||||||
|
TreeItemContainer,
|
||||||
|
(prevProps, nextProps) => {
|
||||||
|
const id = prevProps.treeNode.id;
|
||||||
|
return (
|
||||||
|
prevProps.treeNode === nextProps.treeNode &&
|
||||||
|
id !== prevProps.selectedNode &&
|
||||||
|
id !== nextProps.selectedNode
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
function TreeItemContainer({
|
function TreeItemContainer({
|
||||||
innerRef,
|
innerRef,
|
||||||
isUsingKBToScroll,
|
isUsingKBToScroll,
|
||||||
|
|||||||
Reference in New Issue
Block a user