Skip to content

Commit

Permalink
Improve throttling function
Browse files Browse the repository at this point in the history
  • Loading branch information
paator committed Aug 13, 2023
1 parent 3c39c32 commit 02a9311
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/components/ModuleEditor/PatternEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ function PatternEditor() {
}
};

const handleWheel = (e: React.WheelEvent<HTMLDivElement>) => {
if (e.deltaY < 0) {
decrementY(1);
} else {
incrementY(1);
}
};
const onWheelThrottled = useMemo(() => {
const handleWheel = (e: React.WheelEvent<HTMLDivElement>) => {
if (e.deltaY < 0) {
decrementY(1);
} else {
incrementY(1);
}
};

const onWheelThrottled = useMemo(() => throttle(handleWheel, 20), []);
return throttle(handleWheel, 20);
}, [decrementY, incrementY]);

return (
<div
Expand Down

0 comments on commit 02a9311

Please sign in to comment.