Skip to content

Commit 19eeb4b

Browse files
authored
fix: preserve this context in debounce (#1090)
1 parent 5f32a7b commit 19eeb4b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

app/utils/misc.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,15 @@ export function useDoubleCheck() {
242242
function debounce<Callback extends (...args: Parameters<Callback>) => void>(
243243
fn: Callback,
244244
delay: number,
245-
) {
245+
): (this: ThisParameterType<Callback>, ...args: Parameters<Callback>) => void {
246246
let timer: ReturnType<typeof setTimeout> | null = null
247-
return (...args: Parameters<Callback>) => {
247+
return function (
248+
this: ThisParameterType<Callback>,
249+
...args: Parameters<Callback>
250+
) {
248251
if (timer) clearTimeout(timer)
249252
timer = setTimeout(() => {
250-
fn(...args)
253+
fn.apply(this, args)
251254
}, delay)
252255
}
253256
}

0 commit comments

Comments
 (0)