-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(query-core): do not fetch if queryFn is skipToken #9301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
our usual stance is that imperative functions don’t need those guards because you can wrap them in an |
also, we would need this on |
thanks for your reply. I agree with you, but what's the idiomatic way to conditionally prefetch a query in react hooks since it cannot use |
we had the same question come up regarding |
I use it to initiate anticipated requests in advance to reduce the time consumed by waterfall requests. I believe I can implement it using a different approach, such as useEffect combined with if(id). I'm just curious why we're allowed to pass skipToken to usePrefetchQuery but receive an error at the end. |
yeah we should fix that on type level. like we’ve done it in |
the docs also say:
with suspense, you also have no |
thank you for your clarification. in my scenario, I receive an optional id from the url. there is a nested component tree that will cause waterfall queries. therefore, I want to prefetch some data that will be necessary. the detail list and feedback list are two APIs fetched by collection id and connected by the detail id. feedback is loaded after the message is rendered, without prefetching. <Collection id={optionalCollectionId}>
{prefetchFeedbacks}
<Suspense>
<List>
<Detail>
<Feedback /> {/* select: feedbacks => feedbacks.find(fb => fb.detailId === detail.id) */}
</Detail>
<Detail>
<Feedback />
</Detail>
...
</List>
</Suspense>
</Collection>
function Detail({ collectionId, detail }) {
const { data: feedback } = useQuery({
queryKey: ['feedbacks', collectionId],
queryFn: () => fetchFeedbacks(collectionId),
select: feedbacks => feedbacks.find(fb => fb.detailId === detail.id),
});
return <>{/* ... */}</>;
} |
sometimes I want to call prefetch with a condition:
Repro:
but there will be an error: