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

use-throttle

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-throttle - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

17

lib/index.js

@@ -18,19 +18,14 @@ 'use strict';

var _useState3 = (0, _react.useState)(Date.now()),
_useState4 = _slicedToArray(_useState3, 2),
lastRan = _useState4[0],
setLastRan = _useState4[1];
var lastRan = (0, _react.useRef)(Date.now());
var handler = (0, _react.useRef)();
(0, _react.useEffect)(function () {
handler.current = setTimeout(function () {
if (Date.now() - lastRan >= limit) {
var handler = setTimeout(function () {
if (Date.now() - lastRan.current >= limit) {
setThrottledValue(value);
setLastRan(Date.now());
lastRan.current = Date.now();
}
}, limit - (Date.now() - lastRan));
}, limit - (Date.now() - lastRan.current));
return function () {
clearTimeout(handler.current);
clearTimeout(handler);
};

@@ -37,0 +32,0 @@ }, [value, limit]);

{
"name": "use-throttle",
"version": "0.0.2",
"version": "0.0.3",
"description": "Throttle hook for react",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -5,16 +5,15 @@ import { useState, useEffect, useRef } from 'react';

const [throttledValue, setThrottledValue] = useState(value);
const [lastRan, setLastRan] = useState(Date.now());
const handler = useRef();
const lastRan = useRef(Date.now());
useEffect(
() => {
handler.current = setTimeout(function() {
if (Date.now() - lastRan >= limit) {
const handler = setTimeout(function() {
if (Date.now() - lastRan.current >= limit) {
setThrottledValue(value);
setLastRan(Date.now());
lastRan.current = Date.now();
}
}, limit - (Date.now() - lastRan));
}, limit - (Date.now() - lastRan.current));
return () => {
clearTimeout(handler.current);
clearTimeout(handler);
};

@@ -21,0 +20,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