TanStackT
TanStack10mo ago
5 replies
colossal-harlequin

When to use tanstack query for loader functions

Hey all,

Following the example here: https://tanstack.com/router/v1/docs/framework/react/guide/external-data-loading

I am using ensureQueryData in my loader to fetch data.

I am questioning the benefit of using loader functions in my app at all, its a complete SPA. Using this method, Im not a fan of missing out on some of the typical react query functionality, such as refetching on window focus.

Wondering what the use case is for loaderFn? I find I would have much more rich functionality just fetching in my components, considering my app is a SPA. But wanted to hear other opinions!
[!IMPORTANT] This guide is geared towards external state management libraries and their integration with TanStack Router for data fetching, ssr, hydration/dehydration and streaming. If you haven't rea...
External Data Loading | TanStack Router React Docs
Was this page helpful?