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!React TanStack Start Start Basic React Query) Example | TanStack St...
An example showing how to implement Start Basic React Query) in React using TanStack Start.
2 Replies
sensitive-blue•3mo ago
useQuery does not run on the server
hence the function wont run on the server
either use useSuspenseQuery or call queryClient.ensureQueryData (or similar) in a loader
genetic-orangeOP•3mo ago
Thanks!