Throttle instead of debounce (#4456)

* throttle instead of debounce

* trailing: true

* Fix throttle call

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
This commit is contained in:
Samuel Newman
2024-06-10 16:02:57 +01:00
committed by GitHub
parent 1317d881ed
commit fd03ea3fe1
@@ -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],
)