Data Loading with Start
I have a couple questions about how to load data with Tanstack Start/Router. I think the crux of my confusion is around whether the
loader
function runs on the client or server. It seems like the answer is both, but I'm sure how to think through the implications of that.
1) We currently use Redux as an API cache & we're hoping to use Tanstack Start as a way to essentially "pre-warm" our Redux store. So the idea is that we use Tanstack loaders to fetch the data on load immediately, then send it straight to Redux & use redux selectors to render our components. It seems like this page covers this usecase (https://tanstack.com/router/latest/docs/framework/react/guide/external-data-loading), but I'm not sure exactly how I would do this with Redux. Do I call dispatch
inside loader
function. Is that going to work if loader
is being run on the server? Is there some kind of afterLoad
function that I can call after loader returns but before the component renders?
2) How can I access request headers inside loader
? I need to access headers to properly load data, but that's only relevant for the initial SSR request. Do I use server functions for this? Ideally I want to be able to say: if this is the initial SSR load, then give me the header, otherwise give me undefined.
Thanks!0 Replies