Skip to content

Commit e055f95

Browse files
authored
Use debounce instead of fixed interval
1 parent 67d08c6 commit e055f95

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/useObserver.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ let reactionCleanupHandle: number | undefined
7878

7979
function scheduleCleanupOfReactionIfNotCommitted(reaction: Reaction) {
8080
uncommittedReactions.push(reaction)
81-
if (!reactionCleanupHandle) {
82-
// We currently have no cleanup timer running; schedule one
83-
reactionCleanupHandle = window.setTimeout(cleanUncommittedReactions, 100)
81+
if (reactionCleanupHandle) {
82+
window.clearTimeout(reactionCleanupHandle)
8483
}
84+
// We currently have no cleanup timer running; schedule one
85+
reactionCleanupHandle = window.setTimeout(cleanUncommittedReactions, 100)
8586
}
8687

8788
function recordReactionAsCommitted(reaction: Reaction) {

0 commit comments

Comments
 (0)