Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿

refactor: optimize usePreventScrollOnNumberInput hook by extracting preventScroll function into useCallback for improved performance and clarity

yoginth.com 5f83f43d 19290b22

verified
+7 -7
+7 -7
apps/web/src/hooks/usePreventScrollOnNumberInput.tsx
··· 1 1 import type { RefObject } from "react"; 2 - import { useEffect } from "react"; 2 + import { useCallback, useEffect } from "react"; 3 3 4 4 const usePreventScrollOnNumberInput = ( 5 5 ref: RefObject<HTMLInputElement> 6 6 ): void => { 7 + const preventScroll = useCallback((event: WheelEvent) => { 8 + event.preventDefault(); 9 + event.stopPropagation(); 10 + }, []); 11 + 7 12 useEffect(() => { 8 13 const input = ref.current; 9 14 10 - const preventScroll = (event: WheelEvent) => { 11 - event.preventDefault(); 12 - event.stopPropagation(); 13 - }; 14 - 15 15 if (input) { 16 16 input.addEventListener("wheel", preventScroll, { passive: false }); 17 17 } ··· 21 21 input.removeEventListener("wheel", preventScroll); 22 22 } 23 23 }; 24 - }, [ref]); 24 + }, [ref, preventScroll]); 25 25 }; 26 26 27 27 export default usePreventScrollOnNumberInput;