TanStackT
TanStack3y ago
1 reply
worthy-azure

fetch and consume data during ssr process

Hi, my goal is to fetch external data and share the result to a prefetchInfiniteQuery() and all that during ssr

data is fetched from there

export default async function useGetProjects() { const queryClient = getQueryClient(); await queryClient.fetchQuery({ queryKey: useProjectQueryKey.all, queryFn: getProjects }); return queryClient; }` and consume here export default async function useGetTodos() {
const queryClient = getQueryClient();
const projects = await useGetProjects();

await queryClient.prefetchInfiniteQuery({
queryKey: useTodoQueryKey.infinite(),
queryFn: ({ pageParam }) =>
getTodos({
cursor: pageParam,
initiatorId: projects[0].id
}),
initialPageParam: 0
});

return queryClient;
}`

but projects is a QueryClient instead of TData :/
according to https://tanstack.com/query/latest/docs/react/reference/QueryClient#queryclientfetchquery

thanks
QueryClient

The QueryClient can be used to interact with a cache:
Was this page helpful?