Update debounce behaviour when hovering over list items

This commit is contained in:
Timothy Armes
2023-07-20 08:50:34 +02:00
parent 6baa63c23d
commit 70b685fa99
2 changed files with 3 additions and 8 deletions
+2 -7
View File
@@ -3,7 +3,7 @@ import { atom, SetStateAction } from "jotai";
export default function atomWithDebounce<T>(
initialValue: T,
delayMilliseconds = 500,
shouldDebounceOnReset = false,
delayOnResetMilliseconds = 500,
) {
const prevTimeoutAtom = atom<ReturnType<typeof setTimeout> | undefined>(
undefined,
@@ -37,14 +37,9 @@ export default function atomWithDebounce<T>(
onDebounceStart();
if (!shouldDebounceOnReset && nextValue === initialValue) {
onDebounceEnd();
return;
}
const nextTimeoutId = setTimeout(() => {
onDebounceEnd();
}, delayMilliseconds);
}, nextValue === initialValue ? delayOnResetMilliseconds : delayMilliseconds);
// set previous timeout atom in case it needs to get cleared
set(prevTimeoutAtom, nextTimeoutId);