Skip to content

Commit

Permalink
usePreviewTransactions debounce fix
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Oct 18, 2024
1 parent 305ce81 commit ca5be2b
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions packages/loot-core/src/client/data-hooks/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ca5be2b

Please sign in to comment.