Skip to content

Commit

Permalink
Simplify hook logic for mouse-down in image resizer
Browse files Browse the repository at this point in the history
  • Loading branch information
sjdemartini committed Jun 24, 2024
1 parent 21f6017 commit b33c028
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/extensions/ResizableImageResizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,18 @@ export function ResizableImageResizer({
const { classes, cx } = useStyles();

useEffect(() => {
if (!mouseDown) {
return;
}

// If the user is currently holding down the resize handle, we'll have mouse
// movements fire the onResize callback (since the user would be "dragging"
// the handle).
const handleMouseMove = (event: MouseEvent) => {
onResize(event);
};

if (mouseDown) {
// If the user is currently holding down the resize handle, we'll have mouse
// movements fire the onResize callback (since the user would be "dragging" the
// handle)
window.addEventListener("mousemove", handleMouseMove);
}

window.addEventListener("mousemove", handleMouseMove);
return () => {
window.removeEventListener("mousemove", handleMouseMove);
};
Expand Down

0 comments on commit b33c028

Please sign in to comment.