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
I followed the guide here https://trpc.io/docs/ssr
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.
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.