From fce83312fb4302d1d4fd94c4ef3cbae4758dbf1e Mon Sep 17 00:00:00 2001 From: "Guillermo O. Freschi" Date: Mon, 15 Jan 2024 18:28:00 -0300 Subject: [PATCH 1/2] Accept first change on throttle If sending data too quickly at the start of the hook, it would never accept a first value. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f6e4fe2..6a2fc90 100644 --- a/index.js +++ b/index.js @@ -1244,8 +1244,8 @@ export function useThrottle(value, interval = 500) { React.useEffect(() => { const now = Date.now(); - - if (lastUpdated.current && now >= lastUpdated.current + interval) { + + if (!lastupdated.current || now >= lastUpdated.current + interval) { lastUpdated.current = now; setThrottledValue(value); } else { From 83e57028796bbd1fdb1df9a49c25bef6facc4d2c Mon Sep 17 00:00:00 2001 From: "Guillermo O. Freschi" Date: Mon, 15 Jan 2024 18:29:36 -0300 Subject: [PATCH 2/2] Fix extra space --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6a2fc90..19abdbf 100644 --- a/index.js +++ b/index.js @@ -1244,7 +1244,7 @@ export function useThrottle(value, interval = 500) { React.useEffect(() => { const now = Date.now(); - + if (!lastupdated.current || now >= lastUpdated.current + interval) { lastUpdated.current = now; setThrottledValue(value);