From 24854ac00ff18ced6f97df884fff58c0e3ad2ecc Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Wed, 15 Nov 2023 17:57:01 +0300 Subject: [PATCH] Fix debounce for ssr --- src/functions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions.ts b/src/functions.ts index 251cb507..ae5379ae 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -3,7 +3,7 @@ export const noop = () => {}; // eslint-disable-line @typescript-eslint/no-empty export function throttle( fn: (...args: T) => unknown, threshold = 50, - scope = window, + scope = typeof window !== 'undefined' ? window : undefined, ) { let prevDate: number = Date.now() - threshold; let timeoutId: ReturnType; @@ -34,7 +34,7 @@ export function throttle( export function debounce( fn: (...args: T) => unknown, delay: number, - context = window, + context = typeof window !== 'undefined' ? window : undefined, ) { let timeoutId: ReturnType; let args: T;