Hello

I am getting TypeError: Cannot read properties of null (reading 'useContext') When trying to getServerSideProps in next export const getServerSideProps = () => { const protect = api.text2img.protect.useQuery(); console.log(protect); // Pass data to the page via props return { props: { data: "what" } } }
3 Replies
mid
midOP•3y ago
I followed the guide here https://trpc.io/docs/ssr
mid
midOP•3y ago
I followed the guide here https://trpc.io/docs/ssr
Server-Side Rendering | tRPC
To enable SSR just set ssr: true in your createTRPCNext config callback.
devjo-ca
devjo-ca•3y ago
you can't use the useQuery or useMutation inside the serverSideProps. If you wan't to call trpc inside the getServerSideProps you must take a look on the ssg helper 🙂 https://trpc.io/docs/ssg-helpers#nextjs-example
SSG Helpers | tRPC
createProxySSGHelpers provides you with a set of helper functions that you can use to prefetch queries on the server.

Did you find this page helpful?