T
TanStack16mo ago
rare-sapphire

Running a query function without useQuery

I have the following query function. How can I run this outside of a React component (e.g. loader function of a route from TanStack Router), so that it still gets cached as if evoked through useQuery hook?
const query = async (): Promise<CurrentUserResponse> => {
return await GET('/current_user');
};
const query = async (): Promise<CurrentUserResponse> => {
return await GET('/current_user');
};
3 Replies
adverse-sapphire
adverse-sapphire16mo ago
queryClient.prefetchQuery
rare-sapphire
rare-sapphireOP16mo ago
I believe this should be the queryClient instance passed to QueryClientProvider, right?
adverse-sapphire
adverse-sapphire16mo ago
yes

Did you find this page helpful?