timmm
CCConvex Community
•Created by timmm on 9/9/2024 in #support-community
Tanstack + Realtime not working
That was it. Thanks Tom 🙂
9 replies
CCConvex Community
•Created by timmm on 9/9/2024 in #support-community
Tanstack + Realtime not working
Yep I'm using the ConvexQueryClient - here's main.tsx
import ReactDOM from "react-dom/client";
import { RouterProvider, createRouter } from "@tanstack/react-router";
import { ConvexQueryClient } from "@convex-dev/react-query";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ConvexAuthProvider } from "@convex-dev/auth/react";
import { ConvexReactClient, useConvexAuth } from "convex/react";
import { api } from "backend/convex/_generated/api";
import "./tailwind.css";
// Setup Convex with Tanstack Query
const convex = new ConvexReactClient(import.meta.env.VITE_CONVEX_URL);
const convexQueryClient = new ConvexQueryClient(convex);
const queryClient = new QueryClient({
defaultOptions: {
queries: {
queryKeyHashFn: convexQueryClient.hashFn(),
queryFn: convexQueryClient.queryFn(),
},
},
});
// Import the generated route tree
import { routeTree } from "./routeTree.gen";
// Create a new router instance
const router = createRouter({
routeTree,
context: {
api: api,
queryClient: queryClient,
auth: undefined,
},
defaultPreload: "intent",
defaultPreloadStaleTime: 0,
});
// Register the router instance for type safety
declare module "@tanstack/react-router" {
interface Register {
router: typeof router;
}
}
// eslint-disable-next-line react-refresh/only-export-components
function App() {
const auth = useConvexAuth();
return (
<RouterProvider
router={router}
defaultPreload="intent"
context={{
auth,
}}
/>
);
}
// Render the app
const rootElement = document.getElementById("root")!;
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement);
root.render(
<ConvexAuthProvider client={convex}>
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</ConvexAuthProvider>,
);
}
import ReactDOM from "react-dom/client";
import { RouterProvider, createRouter } from "@tanstack/react-router";
import { ConvexQueryClient } from "@convex-dev/react-query";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { ConvexAuthProvider } from "@convex-dev/auth/react";
import { ConvexReactClient, useConvexAuth } from "convex/react";
import { api } from "backend/convex/_generated/api";
import "./tailwind.css";
// Setup Convex with Tanstack Query
const convex = new ConvexReactClient(import.meta.env.VITE_CONVEX_URL);
const convexQueryClient = new ConvexQueryClient(convex);
const queryClient = new QueryClient({
defaultOptions: {
queries: {
queryKeyHashFn: convexQueryClient.hashFn(),
queryFn: convexQueryClient.queryFn(),
},
},
});
// Import the generated route tree
import { routeTree } from "./routeTree.gen";
// Create a new router instance
const router = createRouter({
routeTree,
context: {
api: api,
queryClient: queryClient,
auth: undefined,
},
defaultPreload: "intent",
defaultPreloadStaleTime: 0,
});
// Register the router instance for type safety
declare module "@tanstack/react-router" {
interface Register {
router: typeof router;
}
}
// eslint-disable-next-line react-refresh/only-export-components
function App() {
const auth = useConvexAuth();
return (
<RouterProvider
router={router}
defaultPreload="intent"
context={{
auth,
}}
/>
);
}
// Render the app
const rootElement = document.getElementById("root")!;
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement);
root.render(
<ConvexAuthProvider client={convex}>
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</ConvexAuthProvider>,
);
}
9 replies
CCConvex Community
•Created by timmm on 9/9/2024 in #support-community
Tanstack + Realtime not working
Looking at the network requests in the websocket it's adding the query and then immediately removing it
9 replies