Skip to content
Discussion options

You must be logged in to vote

what I would do is not debounce the function, but debounce the piece of state that goes into the query key. every query key change triggers a new cache entry, and just because you debounce the the queryFn that doesn't mean that they are then batched together. They represent separate cache entries, which have already been created.

Here is a good example for use-debounce: https://usehooks.com/useDebounce/

It would be something like this:

const [someVar, setSomeVar] = React.useState()
const debouncedVar = useDebounce(someVar, 2000)

useQuery([debouncedVar, currentSiteState], ...)

since the debouncedVar doesn't change during the debounce time, the key stays the same and nothing happens. Then…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by TkDodo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants