T
TanStack•4y ago
unwilling-turquoise

Using hydration

I've used this code in my next 12 app: https://tanstack.com/query/v4/docs/guides/ssr#using-hydration But my fetching function uses prisma. Thing is, Prisma cannot be called in the client. So I can't use "useQuery" with it. How should I write my code then? not using hydration and just doing useQuery on my getServerSideProps, without hydration thing?
SSR | TanStack Query Docs
React Query supports two ways of prefetching data on the server and passing that to the queryClient. Prefetch the data yourself and pass it in as initialData
3 Replies
broad-brown
broad-brown•4y ago
The function you use on the server does not have to be the same as the function you use on the client
unwilling-turquoise
unwilling-turquoiseOP•4y ago
Yea but the function is need one that uses prisma to fetch, so I need that on my client as well
broad-brown
broad-brown•4y ago
- you make one function that gets data from prisma - you use that function in gSSP on the server - you create an api endpoint that uses that function - you call the api endpoint on the client this has nothing to do with react-query - you have to do the same thing if you were to fetch with axios in a useEffect and pass data down as props from gSSP 🙂

Did you find this page helpful?