Inconsecutive responses #3408
-
Hi, I'm quite novice to using React-query and I have this combobox -style component that offers automatic completions (from quite large collection) for user as they type in their search terms. The backend response times are so inconsistent I often receive the results from older requests after newest call finishes. I haven't been able to yet find bulletproof solution to ensure correct sequence. I believe adding Perhaps my only option is to attach sequence number (or timestamp) to my I'm sure many have struggled with the same problem, any advice and/or code examples? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The important part is that you add the search parameters to the query key (all "dependencies" to the query should go to the query key!). Then, if the search input changes, react-query will automatically fire off a new request. The old request can finish later, and it will be put into the cache, but under a different cache key, which will make it not interfere with your currently displayed result. |
Beta Was this translation helpful? Give feedback.
The important part is that you add the search parameters to the query key (all "dependencies" to the query should go to the query key!). Then, if the search input changes, react-query will automatically fire off a new request. The old request can finish later, and it will be put into the cache, but under a different cache key, which will make it not interfere with your currently displayed result.