How would I go about cancelling a query prefetch? #8457
-
I have some code like so: function getDataFromServer(context) {
return axios.get(`/url/${context.queryKey[1]}`, { signal });
}
function useMyQuery(n) {
usePrefetchQuery({ queryKey: ["url", n-1], queryFn: getDataFromServer });
usePrefetchQuery({ queryKey: ["url", n+1], queryFn: getDataFromServer });
return useQuery({ queryKey: ["url", n], queryFn: getDataFromServer });
} (My code is more complicated, but I think this suffices for an example) So that users don't have to see loading when changing the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
yep. |
Beta Was this translation helpful? Give feedback.
yep.
queryClient.cancelQueries(...)