TanStackT
TanStack12mo ago
10 replies
living-lavender

useQuery to get data in nested route

I've been using
useQuery
without a queryFn but say query key to get the data and status information about the query in a components outside where I supply the queryFn [I thought this was supported behavior, let me know if it isn't]. If I have a path like reports/$reportId I have the
useQuery
with the queryFn at the "reports" level, but then
useQuery
without queryFn at the "$reportId" level. When I navigate from /reports to /reports/$reportId this all works fine, but if I go directly to /reports/$reportId the queryFn is never called. If I avoid rendering the outlet in /reports until after the query is finished it does work. Is this expect? Is there a way to do this without the conditional rendering of the outlet? Is there another setup that is more correct?
Was this page helpful?