diff --git a/app/atoms.ts b/app/atoms.ts index 346bd27..17ae238 100644 --- a/app/atoms.ts +++ b/app/atoms.ts @@ -22,7 +22,7 @@ export const { } = atomWithDebounce(null); export const { debouncedValueAtom: debouncedHoveredListTournamentIdAtom } = - atomWithDebounce(null, 300, true); + atomWithDebounce(null, 1000, 100); export const filteredTournamentsByTimeControlAtom = atom((get) => { const tournaments = get(tournamentsAtom); diff --git a/utils/atomWithDebounce.ts b/utils/atomWithDebounce.ts index 75001bb..3765983 100644 --- a/utils/atomWithDebounce.ts +++ b/utils/atomWithDebounce.ts @@ -3,7 +3,7 @@ import { atom, SetStateAction } from "jotai"; export default function atomWithDebounce( initialValue: T, delayMilliseconds = 500, - shouldDebounceOnReset = false, + delayOnResetMilliseconds = 500, ) { const prevTimeoutAtom = atom | undefined>( undefined, @@ -37,14 +37,9 @@ export default function atomWithDebounce( 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);