TanStackT
TanStack12mo ago
1 reply
dead-brown

useQuery with server function?

Hello - I ran into something I didn't know how to handle. I am trying to make a query - but I am passing the
db
in the query options. However, this gets ran in the client so - pg can't be called there. What is the proper way to handle this in Tanstack Start with
useQuery
or
queryClient
perhaps?

// some file import { db } from "~/server/db"; export const MESSAGE_LIST_QUERY_KEY = ["messages"]; const sessionHistoryQueryOptions = () => queryOptions({ queryKey: MESSAGE_LIST_QUERY_KEY, queryFn: () => getAllSessionHistory(db), }); export default sessionHistoryQueryOptions; // in another file // does not work. pg can't be called in the client const { data: messages } = useQuery(sessionHistoryQueryOptions());
Was this page helpful?