Fix bug in tree when search term is set

Summary: Previously we would run the effect even if search term hadnt changed causing us to scorll to a search term rather than the selected node when selecting in the visualiser

Reviewed By: antonk52

Differential Revision: D47831188

fbshipit-source-id: 5700d49aea219a1229bcc8df462e55d8508c6c1a
This commit is contained in:
Luke De Feo
2023-08-01 06:41:14 -07:00
committed by Facebook GitHub Bot
parent 382ee6de35
commit 21483986c3

View File

@@ -114,7 +114,12 @@ export function Tree2({
overscan: 20,
});
const prevSearchTerm = useRef<string | null>(null);
useEffect(() => {
if (prevSearchTerm.current === searchTerm) {
return;
}
prevSearchTerm.current = searchTerm;
const matchingIndexes = findSearchMatchingIndexes(treeNodes, searchTerm);
if (matchingIndexes.length > 0) {