Skip to content

Commit d65ce3e

Browse files
Use useCallback when calling toggleExpanded
1 parent eebe11e commit d65ce3e

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

extensions/ql-vscode/src/view/results/AlertTablePathRow.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { selectableZebraStripe } from "./result-table-utils";
55
import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
66
import { AlertTablePathNodeRow } from "./AlertTablePathNodeRow";
77
import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCell";
8-
import { useMemo } from "react";
8+
import { useCallback, useMemo } from "react";
99

1010
interface Props {
1111
path: Sarif.ThreadFlow;
@@ -37,8 +37,8 @@ export function AlertTablePathRow(props: Props) {
3737
() => ({ resultIndex, pathIndex }),
3838
[pathIndex, resultIndex],
3939
);
40-
const handleDropdownClick = useMemo(
41-
() => (e: React.MouseEvent) => toggleExpanded(e, [pathKey]),
40+
const handleDropdownClick = useCallback(
41+
(e: React.MouseEvent) => toggleExpanded(e, [pathKey]),
4242
[pathKey, toggleExpanded],
4343
);
4444

extensions/ql-vscode/src/view/results/AlertTableResultRow.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { info, listUnordered } from "./octicons";
55
import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
66
import { selectableZebraStripe } from "./result-table-utils";
77
import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCell";
8-
import { useMemo } from "react";
8+
import { useCallback, useMemo } from "react";
99
import { SarifLocation } from "./locations/SarifLocation";
1010
import { SarifMessageWithLocations } from "./locations/SarifMessageWithLocations";
1111
import { AlertTablePathRow } from "./AlertTablePathRow";
@@ -46,15 +46,18 @@ export function AlertTableResultRow(props: Props) {
4646
() => updateSelectionCallback(resultKey),
4747
[resultKey, updateSelectionCallback],
4848
);
49-
const handleDropdownClick = useMemo(() => {
50-
const indices =
51-
Keys.getAllPaths(result).length === 1
52-
? [resultKey, { ...resultKey, pathIndex: 0 }]
53-
: /* if there's exactly one path, auto-expand
54-
* the path when expanding the result */
55-
[resultKey];
56-
return (e: React.MouseEvent) => toggleExpanded(e, indices);
57-
}, [result, resultKey, toggleExpanded]);
49+
const handleDropdownClick = useCallback(
50+
(e: React.MouseEvent) => {
51+
const indices =
52+
Keys.getAllPaths(result).length === 1
53+
? [resultKey, { ...resultKey, pathIndex: 0 }]
54+
: /* if there's exactly one path, auto-expand
55+
* the path when expanding the result */
56+
[resultKey];
57+
toggleExpanded(e, indices);
58+
},
59+
[result, resultKey, toggleExpanded],
60+
);
5861

5962
const resultRowIsSelected =
6063
selectedItem?.resultIndex === resultIndex &&

0 commit comments

Comments
 (0)