#Avoiding fetch many times when fetching by text?

4 messages · Page 1 of 1 (latest)

molten moss
#

I have a react-query hook that goes like this:

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?

#

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

tough monolith
#

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