T
TanStack2y ago
sunny-green

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 | TanStack Query Docs
QueryClient The QueryClient can be used to interact with a cache:
1 Reply
optimistic-gold
optimistic-gold2y ago
You are returning the queryclient instead of the value returned by fetchQuery in useGetProjects

Did you find this page helpful?