@nextui-org/use-scroll-position
Advanced tools
Comparing version 2.0.5 to 2.0.6
type ScrollValue = { | ||
x: any; | ||
y: any; | ||
x: number; | ||
y: number; | ||
}; | ||
@@ -5,0 +5,0 @@ interface UseScrollPositionOptions { |
@@ -41,4 +41,4 @@ "use strict"; | ||
); | ||
let throttleTimeout = null; | ||
const handler = () => { | ||
const throttleTimeout = (0, import_react.useRef)(null); | ||
const handler = (0, import_react.useCallback)(() => { | ||
const currPos = getScrollPosition(elementRef == null ? void 0 : elementRef.current); | ||
@@ -49,4 +49,4 @@ if (typeof callback === "function") { | ||
position.current = currPos; | ||
throttleTimeout = null; | ||
}; | ||
throttleTimeout.current = null; | ||
}, [callback, elementRef]); | ||
(0, import_react.useEffect)(() => { | ||
@@ -57,4 +57,4 @@ if (!isEnabled) | ||
if (delay) { | ||
if (throttleTimeout === null) { | ||
throttleTimeout = setTimeout(handler, delay); | ||
if (throttleTimeout.current === null) { | ||
throttleTimeout.current = setTimeout(handler, delay); | ||
} | ||
@@ -67,4 +67,9 @@ } else { | ||
target.addEventListener("scroll", handleScroll); | ||
return () => target.removeEventListener("scroll", handleScroll); | ||
}, [elementRef == null ? void 0 : elementRef.current, delay, isEnabled]); | ||
return () => { | ||
target.removeEventListener("scroll", handleScroll); | ||
if (throttleTimeout.current) { | ||
clearTimeout(throttleTimeout.current); | ||
} | ||
}; | ||
}, [elementRef == null ? void 0 : elementRef.current, delay, handler, isEnabled]); | ||
return position.current; | ||
@@ -71,0 +76,0 @@ }; |
{ | ||
"name": "@nextui-org/use-scroll-position", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "Provides the logic to control the scroll over an element", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8136
155