T
TanStack6mo ago
adverse-sapphire

How do I use a form with React Query for debounced search/filter?

I just tried using TanStack React Form, and I want to use it with React Query for a searching feature. But how can I get a debounced value that I can pass to React Query to reduce requests on change? Should I use a custom hook, or does TanStack Form have that feature?
3 Replies
wise-white
wise-white6mo ago
Tanstack form does have that feature, but not for your use case. The form validators support debouncing to reduce async calls, you can read more on it here However, you seem to be looking for debouncing of useQuery calls, which is unrelated to tanstack form. As far as I'm aware, it's also not something that useQuery supports natively. The React useEffect hook allows you to create a custom debounce somewhat easily. I recommend reading up on it in this article
adverse-sapphire
adverse-sapphireOP6mo ago
Okay bro, so I should use a custom hook.
wise-white
wise-white6mo ago
Yes :PepeThumbs:

Did you find this page helpful?