T
TanStack3mo ago
optimistic-gold

Question about loader / beforeLoading

So what do I do in this type of case :
/$id
route.tsx <-- Need to fetch some data about related to the $id
path-a.tsx
path-b.tsx. <-- Need to access the `route.tsx` data in its own `loader()`.
/$id
route.tsx <-- Need to fetch some data about related to the $id
path-a.tsx
path-b.tsx. <-- Need to access the `route.tsx` data in its own `loader()`.
If I put my dataloading in the beforeLoad of the route.tx, I can pass it in the context and all is fine, the children paths have assess to it. But, the beforeLoad seems to refetch every navigation, but I don't want to do that since the information only changes when the $id changes. I know that the loader() are run all at the same time for the routes so the children cannot access the data of the parent in their loader(), so what should I do ?
2 Replies
sensitive-blue
sensitive-blue3mo ago
load the data in beforeLoad using tanstack query and cache it using that
optimistic-gold
optimistic-goldOP3mo ago
and let the beforeLoad get called everytime, but it will hit cache so we good ?

Did you find this page helpful?