@react-hook/throttle
Advanced tools
Comparing version 2.1.3 to 2.1.4
@@ -18,2 +18,4 @@ 'use strict' | ||
const useThrottleCallback = (callback, fps = 30, leading = false) => { | ||
const storedCallback = useRef(callback) | ||
storedCallback.current = callback | ||
const wait = 1000 / fps | ||
@@ -25,3 +27,3 @@ const prev = useRef(0) | ||
const deps = [callback, fps, leading] // Reset any time the deps change | ||
const deps = [fps, leading] // Reset any time the deps change | ||
@@ -34,3 +36,3 @@ function _ref() { | ||
useEffect(() => _ref, deps) | ||
return useCallback(function here() { | ||
return useCallback(function () { | ||
// eslint-disable-next-line prefer-rest-params | ||
@@ -44,3 +46,3 @@ const args = arguments | ||
callback.apply(null, args) | ||
storedCallback.current.apply(null, args) | ||
} | ||
@@ -60,3 +62,3 @@ | ||
// eslint-disable-next-line prefer-spread | ||
callback.apply(null, args) | ||
storedCallback.current.apply(null, args) | ||
prev.current = 0 | ||
@@ -63,0 +65,0 @@ }, wait) |
@@ -8,2 +8,4 @@ import React from 'react' | ||
export const useThrottleCallback = (callback, fps = 30, leading = false) => { | ||
const storedCallback = useRef(callback) | ||
storedCallback.current = callback | ||
const wait = 1000 / fps | ||
@@ -15,3 +17,3 @@ const prev = useRef(0) | ||
const deps = [callback, fps, leading] // Reset any time the deps change | ||
const deps = [fps, leading] // Reset any time the deps change | ||
@@ -24,3 +26,3 @@ function _ref() { | ||
useEffect(() => _ref, deps) | ||
return useCallback(function here() { | ||
return useCallback(function () { | ||
// eslint-disable-next-line prefer-rest-params | ||
@@ -34,3 +36,3 @@ const args = arguments | ||
callback.apply(null, args) | ||
storedCallback.current.apply(null, args) | ||
} | ||
@@ -50,3 +52,3 @@ | ||
// eslint-disable-next-line prefer-spread | ||
callback.apply(null, args) | ||
storedCallback.current.apply(null, args) | ||
prev.current = 0 | ||
@@ -53,0 +55,0 @@ }, wait) |
{ | ||
"name": "@react-hook/throttle", | ||
"version": "2.1.3", | ||
"version": "2.1.4", | ||
"homepage": "https://github.com/jaredLunde/react-hook/tree/master/packages/throttle#readme", | ||
@@ -5,0 +5,0 @@ "repository": "github:jaredLunde/react-hook", |
@@ -18,2 +18,4 @@ import { | ||
): ((...args: CallbackArguments) => void) => { | ||
const storedCallback = useRef(callback) | ||
storedCallback.current = callback | ||
const wait = 1000 / fps | ||
@@ -25,3 +27,3 @@ const prev = useRef(0) | ||
const clearTrailing = () => clearTimeout(trailingTimeout.current) | ||
const deps = [callback, fps, leading] | ||
const deps = [fps, leading] | ||
@@ -37,3 +39,3 @@ // Reset any time the deps change | ||
return useCallback(function here() { | ||
return useCallback(function () { | ||
// eslint-disable-next-line prefer-rest-params | ||
@@ -46,3 +48,3 @@ const args = arguments | ||
// eslint-disable-next-line prefer-spread | ||
callback.apply(null, args as any) | ||
storedCallback.current.apply(null, args as any) | ||
} | ||
@@ -61,3 +63,3 @@ const current = prev.current | ||
// eslint-disable-next-line prefer-spread | ||
callback.apply(null, args as any) | ||
storedCallback.current.apply(null, args as any) | ||
prev.current = 0 | ||
@@ -64,0 +66,0 @@ }, wait) |
18148
281