Skip to content

Commit 02c7fb1

Browse files
committed
Fixed assumption that elapsed can't be <0
#1464
1 parent 37c68f8 commit 02c7fb1

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

packages/react-hooks/src/useAsyncInterval.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,8 @@ export function useAsyncInterval(
5757

5858
elapsedSinceLastTick += Date.now() - trackingStartedRef.current;
5959

60-
// Calculate any elapsed time beyond the target interval. Note that
61-
// elapsedSinceLastTick should always be >= targetIntervalMs, so overage
62-
// should always be >= 0.
63-
const overage = elapsedSinceLastTick - targetIntervalMs;
60+
// Calculate any elapsed time beyond the target interval.
61+
const overage = Math.max(0, elapsedSinceLastTick - targetIntervalMs);
6462

6563
const nextTickInterval = Math.max(0, targetIntervalMs - overage);
6664

0 commit comments

Comments
 (0)