HudCanvas: add useCallbacks
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-01-13 07:59:48 +01:00
parent 5e27c3db9a
commit aabd0f3252
1 changed files with 89 additions and 83 deletions

View File

@ -174,7 +174,8 @@ export const HudCanvas: React.FC<Props> = ({
return x;
};
const handleMouseDown = (evt: MouseEvent<HTMLCanvasElement>) => {
const handleMouseDown = useCallback(
(evt: MouseEvent<HTMLCanvasElement>) => {
if (mode != Mode.Normal) {
return;
}
@ -197,9 +198,12 @@ export const HudCanvas: React.FC<Props> = ({
moveOffsetX.current = x;
setNewSelection({ start: x, end: x });
}
};
},
[mode, selection]
);
const handleMouseMove = (evt: MouseEvent<HTMLCanvasElement>) => {
const handleMouseMove = useCallback(
(evt: MouseEvent<HTMLCanvasElement>) => {
const x = getCanvasX(evt);
switch (mode) {
@ -267,9 +271,11 @@ export const HudCanvas: React.FC<Props> = ({
break;
}
}
};
},
[mode, selection]
);
const handleMouseUp = () => {
const handleMouseUp = useCallback(() => {
if (mode == Mode.Normal) {
return;
}
@ -283,7 +289,7 @@ export const HudCanvas: React.FC<Props> = ({
}
onSelectionChange({ ...newSelection });
};
}, [mode, newSelection]);
const handleEmptySelectionAction = useCallback(() => {
switch (emptySelectionAction) {