Debounce queryFn on useQuery
I'm trying to implement a search component with
downshift and tanstack-query.
I'm trying to debounce my query function and not my query key as I also need the isLoading state to kick off as the user starts typing, I've had no luck. I've used packages to debounce my queryFn (axios) like lodash debouce, use-debounce but had no luck.
2 Replies
stormy-gold•3y ago
This may help: https://github.com/TanStack/query/issues/293#issuecomment-1308442417
Basically debouncing the query key and comparing the debounced value with the input value to decide on whether to show the loader. Something like :
GitHub
Cannot debounce API calls · Issue #293 · TanStack/query
I am trying to use this for a search component, like: const { status, data, error, isFetching } = useQuery( searchQuery && ['results', searchQuery], getSearchAsync, ...
deep-jade•3y ago
Yeah, I think a comparison between the actual and debounced value is ideal for what you’re describing 👍