diff --git a/package.json b/package.json index 4c4b503..ea19939 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "use-swipe-hook", - "version": "1.0.1", + "version": "1.0.3", "description": "A simple and easy to use tiny library that provides useSwipe hook to use with React that enables swipe gestures for touch screens", "main": "lib/index.umd.js", "browser": "lib/index.umd.js", diff --git a/src/useSwipe.js b/src/useSwipe.js index b39055d..342055b 100644 --- a/src/useSwipe.js +++ b/src/useSwipe.js @@ -17,10 +17,10 @@ const useSwipe = ({ ref, thresholdPX = 5 }) => { }, [x2, y2, thresholdPX]); React.useEffect(() => { - const currentElement = elemRef.current; + const currentElement = ref.current; if (currentElement) { - elemRef.current.addEventListener('touchstart', handleTouchStart); - elemRef.current.addEventListener('touchend', handleTouchEnd); + currentElement.addEventListener('touchstart', handleTouchStart); + currentElement.addEventListener('touchend', handleTouchEnd); } return () => { @@ -29,7 +29,7 @@ const useSwipe = ({ ref, thresholdPX = 5 }) => { currentElement.removeEventListener('touchend', handleTouchEnd); } } - }, [elemRef]); + }, [ref]); function handleTouchStart(event) { setX1(event.changedTouches[0].clientX);