Conditionally calling useQuery + dealing with out of order responses #2396
-
|
Hello, I am using location autocomplete from Geocode Earth 🌏 for an input widget.
LocationInput.tsx getLocationGeocode.ts Thank you 🌊 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
|
Good question! Every time the query input changes, the query is immediately fetched. The first thing that comes to mind is that you need to "debounce" the query input argument. Possibly with https://github.com/xnimorz/use-debounce. Btw, in your query resolver, you will want to return a promise that you manually resolve inside the |
Beta Was this translation helpful? Give feedback.
Good question! Every time the query input changes, the query is immediately fetched. The first thing that comes to mind is that you need to "debounce" the query input argument. Possibly with https://github.com/xnimorz/use-debounce.
Btw, in your query resolver, you will want to return a promise that you manually resolve inside the
res.on("end"handler. As is, it may not work as expected. (or use a different fetcher that uses async/await like https://github.com/sindresorhus/got) Also, is thatuseStatein your resolver from react? If so you shouldn't use it here because the query resolver is outside of react.