T
TanStack•13mo ago
rival-black

No QueryClient set, use QueryClientProvider to set one

I followed the example with-trpc-react-query and the authenticated-routes, combined then but I got this error But I can call trpc query without any issue router.tsx
...
export function createRouter() {
const router = createTanStackRouter({
routeTree,
defaultPreload: "intent",
context: {
trpcQueryUtils,
},
defaultPendingComponent: () => (
<div className={`p-2 text-2xl`}>
<Spinner />
</div>
),
Wrap: function WrapComponent({ children }) {
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
</trpc.Provider>
);
},
});

return router;
}
...
export function createRouter() {
const router = createTanStackRouter({
routeTree,
defaultPreload: "intent",
context: {
trpcQueryUtils,
},
defaultPendingComponent: () => (
<div className={`p-2 text-2xl`}>
<Spinner />
</div>
),
Wrap: function WrapComponent({ children }) {
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
</trpc.Provider>
);
},
});

return router;
}
main.tsx
// Set up a Router instance
const router = createRouter()


function InnerApp() {
const auth = useAuth();
return <RouterProvider router={router} context={{ auth }} />;
}

function App() {
return (
<AuthProvider>
<InnerApp />
</AuthProvider>
);
}


// Render the app
const rootElement = document.getElementById("root")!;
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement);
root.render(
<StrictMode>
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
<App />
</ThemeProvider>
</StrictMode>
);
}
// Set up a Router instance
const router = createRouter()


function InnerApp() {
const auth = useAuth();
return <RouterProvider router={router} context={{ auth }} />;
}

function App() {
return (
<AuthProvider>
<InnerApp />
</AuthProvider>
);
}


// Render the app
const rootElement = document.getElementById("root")!;
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement);
root.render(
<StrictMode>
<ThemeProvider defaultTheme="dark" storageKey="vite-ui-theme">
<App />
</ThemeProvider>
</StrictMode>
);
}
__root.tsx:
interface RouterAppContext {
auth?: AuthContext;
trpcQueryUtils: typeof trpcQueryUtils;
}

export const Route = createRootRouteWithContext<RouterAppContext>()({
component: () => (
<>
<Outlet />
<TanStackRouterDevtools position="bottom-left" />
<ReactQueryDevtools position="bottom" buttonPosition="bottom-right" />
</>
),
});
interface RouterAppContext {
auth?: AuthContext;
trpcQueryUtils: typeof trpcQueryUtils;
}

export const Route = createRootRouteWithContext<RouterAppContext>()({
component: () => (
<>
<Outlet />
<TanStackRouterDevtools position="bottom-left" />
<ReactQueryDevtools position="bottom" buttonPosition="bottom-right" />
</>
),
});
3 Replies
rival-black
rival-blackOP•13mo ago
I m using "@tanstack/react-query": "^5.51.23", "@tanstack/react-router": "^1.45.6", "@trpc/client": "^11.0.0-rc.477", "@trpc/react-query": "^11.0.0-rc.477", "@trpc/server": "^11.0.0-rc.477", "@tanstack/react-query-devtools": "^5.51.23", "@tanstack/router-devtools": "^1.48.1",
flat-fuchsia
flat-fuchsia•13mo ago
do you still facing this problem ?
rival-black
rival-blackOP•13mo ago
since no one gave me an answer yes 🙂 I will try to update the libs tonigh and see it happens I upgraded the libs but still get this error

Did you find this page helpful?