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.2 to 0.0.3

4

package.json
{
"name": "use-throttled-effect",
"version": "0.0.2",
"version": "0.0.3",
"description": "Throttled effect hook for react",

@@ -25,3 +25,3 @@ "main": "lib/index.js",

"peerDependencies": {},
"homepage": "https://github.com/samanamohamadi/use-throttled-effect#readme",
"homepage": "https://github.com/samanmohamadi/use-throttled-effect#readme",
"devDependencies": {

@@ -28,0 +28,0 @@ "babel-cli": "^6.26.0",

@@ -6,3 +6,3 @@ # useThrottledEffect react hook

```
yarn add use-throttled-effect
yarn add use-throttled-effect --save
```

@@ -19,4 +19,3 @@

import React, { useState } from 'react';
import { useThrottledEffect } from 'use-throttled-effect';
import useInterval from '@use-it/interval';
import useThrottledEffect from 'use-throttled-effect';

@@ -26,11 +25,10 @@ export default function Input() {

useEffect(()=>{
const interval = setInterval(() => setCount(count=>count+1) ,100);
return ()=>clearInterval(interval);
},[])
useThrottledEffect(()=>{
console.log(count)
}, 1000,[count]);
// Increment the counter.
useInterval(() => {
setCount(count + 1);
}, 1000);
console.log(count);
}, 1000 ,[count]);

@@ -37,0 +35,0 @@ return (

import { useEffect, useRef } from 'react';
export const useThrottledEffect = (callback, limit, deps = []) => {
// const [throttledValue, setThrottledValue] = useState(value);
const lastRan = useRef(Date.now());

@@ -9,2 +8,3 @@

() => {
console.log([limit, ...deps]);
const handler = setTimeout(function() {

@@ -24,1 +24,3 @@ if (Date.now() - lastRan.current >= limit) {

};
export default useThrottledEffect;
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