From fd03ea3fe1d4f3c6a4079272b0dbd21c4e0d2b1b Mon Sep 17 00:00:00 2001
From: Samuel Newman <mozzius@protonmail.com>
Date: Mon, 10 Jun 2024 16:02:57 +0100
Subject: Throttle instead of debounce (#4456)

* throttle instead of debounce

* trailing: true

* Fix throttle call

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
---
 src/state/queries/messages/list-converations.tsx | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

(limited to 'src/state/queries/messages/list-converations.tsx')

diff --git a/src/state/queries/messages/list-converations.tsx b/src/state/queries/messages/list-converations.tsx
index 306d4cae5..eeab246ab 100644
--- a/src/state/queries/messages/list-converations.tsx
+++ b/src/state/queries/messages/list-converations.tsx
@@ -16,7 +16,7 @@ import {
   useInfiniteQuery,
   useQueryClient,
 } from '@tanstack/react-query'
-import debounce from 'lodash.debounce'
+import throttle from 'lodash.throttle'
 
 import {useCurrentConvoId} from '#/state/messages/current-convo-id'
 import {useMessagesEventBus} from '#/state/messages/events'
@@ -91,7 +91,11 @@ export function ListConvosProviderInner({
   const {currentAccount} = useSession()
 
   const debouncedRefetch = useMemo(
-    () => debounce(() => refetch, 500),
+    () =>
+      throttle(refetch, 500, {
+        leading: true,
+        trailing: true,
+      }),
     [refetch],
   )
 
-- 
cgit 1.4.1

