From 423f7f751d710d942c1f0252789680bed8964162 Mon Sep 17 00:00:00 2001 From: isqua Date: Thu, 26 Oct 2023 12:02:52 +0300 Subject: [PATCH] fix: fixing stuck filtering --- src/features/toc/ui/Menu/Context/hooks.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/features/toc/ui/Menu/Context/hooks.ts b/src/features/toc/ui/Menu/Context/hooks.ts index 19eec9a..9eb3d06 100644 --- a/src/features/toc/ui/Menu/Context/hooks.ts +++ b/src/features/toc/ui/Menu/Context/hooks.ts @@ -47,6 +47,10 @@ export const useFilterInput = () => { const timeout = useRef(0) const onChangeHandler = useCallback((value: string) => { + if (timeout.current) { + clearTimeout(timeout.current) + } + const text = value.trim() if (text === '') { @@ -58,12 +62,8 @@ export const useFilterInput = () => { onFilterStart() } - if (timeout.current) { - clearTimeout(timeout.current) - } - timeout.current = window.setTimeout(() => { - onChange(text) + onChange(text.trim()) }, FILTER_DELAY_IN_MS) }, [isFiltering, onChange, onFilterStart, onReset])