TanStackT
TanStack4mo ago
4 replies
efficient-indigo

How do I run a server function during SSR?

I'm using TS Start with React Query (based on this example https://tanstack.com/start/latest/docs/framework/react/examples/start-basic-react-query) and I want to get a theme cookie during SSR so I don't get a flash of inaccurate color theme.

It looks like if I put the server function in the
loader
it works but doesn't update and if I put it in a
useQuery
it updates dynamically but flashes a null / system theme first.

I could wire up the loader to pass initial data to the query client but I want to make sure I'm not making it too complicated.

Thanks!
An example showing how to implement Start Basic React Query) in React using TanStack Start.
React TanStack Start Start Basic React Query) Example | TanStack St...
Was this page helpful?