useQuery() in recursive component - how to know when all fetches are complete
I'm working on a rendering a tree-like structure (think of nested folders where each folder needs it's own fetch request). What's the best way to know when all the descendant queries are completed to render everything at once?
I first reached for <Suspense> and
useSuspenseQuery()
however useSuspenseQuery()
doesn't support enabled
(there are some reasons why I need to conditionally run the query).3 Replies
flat-fuchsia•14mo ago
Can you render different components when you don't want the query to run? Or does skipToken work with useSuspenseQuery? https://tanstack.com/query/latest/docs/framework/react/guides/disabling-queries/#typesafe-disabling-of-queries-using-skiptoken
What are the reasons why you need to conditionally run the query?
ambitious-aqua•14mo ago
how to know when all fetches are complete
useIsFetching()
returns the count of running fetchesxenial-blackOP•14mo ago
Thanks! I think useIsFetching() might work.
What are the reasons why you need to conditionally run the query?The child components don't need to render based on a signal in the response at the parent level. So the
enabled
param was really helpful for this. It would be great if useSuspenseQuery also supported enabled
but I saw a post somewhere explaining it was an intention decision not to do this.
btw, thanks for all you guys do! RQ is an amazing tool that simplifies FE development.