Skip to content

Commit ee98aaa

Browse files
authored
fix: clear old timers in useDeferredTrigger (#19)
With React 18, useEffect can run twice on mount in strict mode (during development), which would lead to a spurious timer remaining active. The timer always needs to be cleared before a new one is set.
1 parent 2651374 commit ee98aaa

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

src/useDeferredTrigger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export const useDeferredTrigger = (
7575
// We need to wait at least a certain amount of time before
7676
// applying the delay. This can always be canceled by an update
7777
// that re-triggers this effect (as the timeout can be cleared).
78+
clearTimeout(timeoutRef.current)
7879
timeoutRef.current = window.setTimeout(toggleFlag, scheduledDelay)
7980
}
8081
}

0 commit comments

Comments
 (0)