use-throttled-effect
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"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; |
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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1
4085
7
37