From 02a93117771d693b21df837bbc268149095f5c04 Mon Sep 17 00:00:00 2001 From: Kamil Patecki Date: Sun, 13 Aug 2023 23:10:33 +0200 Subject: [PATCH] Improve throttling function --- src/components/ModuleEditor/PatternEditor.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/ModuleEditor/PatternEditor.tsx b/src/components/ModuleEditor/PatternEditor.tsx index ec94309..d9e8602 100644 --- a/src/components/ModuleEditor/PatternEditor.tsx +++ b/src/components/ModuleEditor/PatternEditor.tsx @@ -49,15 +49,17 @@ function PatternEditor() { } }; - const handleWheel = (e: React.WheelEvent) => { - if (e.deltaY < 0) { - decrementY(1); - } else { - incrementY(1); - } - }; + const onWheelThrottled = useMemo(() => { + const handleWheel = (e: React.WheelEvent) => { + if (e.deltaY < 0) { + decrementY(1); + } else { + incrementY(1); + } + }; - const onWheelThrottled = useMemo(() => throttle(handleWheel, 20), []); + return throttle(handleWheel, 20); + }, [decrementY, incrementY]); return (