From ca5be2b75c08ba4c849416cc3fdcf75d3a56cc36 Mon Sep 17 00:00:00 2001 From: Joel Jeremy Marquez Date: Thu, 17 Oct 2024 11:48:14 -0700 Subject: [PATCH] usePreviewTransactions debounce fix --- .../src/client/data-hooks/transactions.ts | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/packages/loot-core/src/client/data-hooks/transactions.ts b/packages/loot-core/src/client/data-hooks/transactions.ts index 93204ac9ac7..86debc3f7b5 100644 --- a/packages/loot-core/src/client/data-hooks/transactions.ts +++ b/packages/loot-core/src/client/data-hooks/transactions.ts @@ -196,19 +196,20 @@ export function useTransactionsSearch({ }: UseTransactionsSearchProps): UseTransactionsSearchResult { const [isSearching, setIsSearching] = useState(false); - const updateSearchQuery = useCallback( - debounce((searchText: string) => { - if (searchText === '') { - resetQuery(); - setIsSearching(false); - } else if (searchText) { - updateQuery(previousQuery => - queries.transactionsSearch(previousQuery, searchText, dateFormat), - ); - setIsSearching(true); - } - }, delayMs), - [dateFormat, resetQuery, updateQuery], + const updateSearchQuery = useMemo( + () => + debounce((searchText: string) => { + if (searchText === '') { + resetQuery(); + setIsSearching(false); + } else if (searchText) { + updateQuery(previousQuery => + queries.transactionsSearch(previousQuery, searchText, dateFormat), + ); + setIsSearching(true); + } + }, delayMs), + [dateFormat, delayMs, resetQuery, updateQuery], ); return {