use-throttled-effect
Advanced tools
Comparing version 0.0.4 to 0.0.5
{ | ||
"name": "use-throttled-effect", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Throttled effect hook for react", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import { useEffect, useRef } from 'react'; | ||
export const useThrottledEffect = (callback, limit, deps = []) => { | ||
export const useThrottledEffect = (callback, delay, deps = []) => { | ||
const lastRan = useRef(Date.now()); | ||
@@ -8,9 +8,8 @@ | ||
() => { | ||
console.log([limit, ...deps]); | ||
const handler = setTimeout(function() { | ||
if (Date.now() - lastRan.current >= limit) { | ||
if (Date.now() - lastRan.current >= delay) { | ||
callback(); | ||
lastRan.current = Date.now(); | ||
} | ||
}, limit - (Date.now() - lastRan.current)); | ||
}, delay - (Date.now() - lastRan.current)); | ||
@@ -21,3 +20,3 @@ return () => { | ||
}, | ||
[limit, ...deps], | ||
[delay, callback, ...deps], | ||
); | ||
@@ -24,0 +23,0 @@ }; |
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
4396
41