#Do I need set queryClient to context in createRouter when use QueryClientProvider?

2 messages · Page 1 of 1 (latest)

worn matrix
#

I already use Tanstack Query with below code:

<QueryClientProvider client={QUERY_CLIENT}>
        <HydrationBoundary state={initialData}>
          <Suspense fallback={PageLoadFallback}>
            <RouterProvider router={router} />
          </Suspense>
        </HydrationBoundary>
</QueryClientProvider>

Do I need to set queryClient to createRouter again?

const QUERY_CLIENT = new QueryClient()

const router = createRouter({
  routeTree: rootRoute,
  context: {
    QUERY_CLIENT,
  },
})
astral token
#

you only "need" to add it to the context if you want to access the query client from router lifecycle methods