Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-throttled-effect

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-throttled-effect - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

2

package.json
{
"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 @@ };

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc