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:
		
							parent
							
								
									1317d881ed
								
							
						
					
					
						commit
						fd03ea3fe1
					
				
					 1 changed files with 6 additions and 2 deletions
				
			
		|  | @ -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], | ||||||
|   ) |   ) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue