T
TanStack3y ago
exotic-emerald

Avoiding fetch many times when fetching by text?

I have a react-query hook that goes like this:
const { data: users, refetch } = useGetUsers({
page,
size: 50,
searchParam,
// enabled: false,
});
const { data: users, refetch } = useGetUsers({
page,
size: 50,
searchParam,
// enabled: false,
});
The problem is, everytime searchParam changes it fetches again. So technically, many users fetching can cause a mini DDoS in this route. Is there a way to delay this fetching until the user stops inputing from keyboard?
3 Replies
exotic-emerald
exotic-emeraldOP3y ago
I want to know if react-query has something bulti-in to handle this, someone figured out that using debounce from lodash but i dislike having to install another lib to handle this So what I'm looking for is pretty much debouncing without another piece of code
xenial-black
xenial-black3y ago
It's out of scope for react-query how you manage the client state. If you want to debounce the searchParams, you have to do it outside of RQ
exotic-emerald
exotic-emeraldOP3y ago
I understand. Thanks

Did you find this page helpful?