Throttle instead of debounce (#4456)

* throttle instead of debounce

* trailing: true

* Fix throttle call

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
zio/stable
Samuel Newman 2024-06-10 16:02:57 +01:00 committed by GitHub
parent 1317d881ed
commit fd03ea3fe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 2 deletions

View File

@ -16,7 +16,7 @@ import {
useInfiniteQuery, useInfiniteQuery,
useQueryClient, useQueryClient,
} from '@tanstack/react-query' } from '@tanstack/react-query'
import debounce from 'lodash.debounce' import throttle from 'lodash.throttle'
import {useCurrentConvoId} from '#/state/messages/current-convo-id' import {useCurrentConvoId} from '#/state/messages/current-convo-id'
import {useMessagesEventBus} from '#/state/messages/events' import {useMessagesEventBus} from '#/state/messages/events'
@ -91,7 +91,11 @@ export function ListConvosProviderInner({
const {currentAccount} = useSession() const {currentAccount} = useSession()
const debouncedRefetch = useMemo( const debouncedRefetch = useMemo(
() => debounce(() => refetch, 500), () =>
throttle(refetch, 500, {
leading: true,
trailing: true,
}),
[refetch], [refetch],
) )