Server side trpc call

Hi, In the attached picture, I am passing username from getserverside props down to my Profile page and I am doing a trpc call to query my db to check if the user exists. This works but I am currently displaying 'user not found' then displaying the user if they exist. I would like to carry out this call on the server so that I can avoid the lag and can display the user or 'user not found' instantly. Do you have any suggestions or tips on how I can carry this out?
13 Replies
cje
cje3y ago
do the query serverside
cje
cje3y ago
SSG Helpers | tRPC
createProxySSGHelpers provides you a set of helper functions that you can use to prefetch queries on the server.
DunnO
DunnOOP3y ago
Thank you for the reply! I am following the documentation and it seems like createContext() expects 'opts' arguments... Do you have any idea what I should pass as the argument in order to initialize ssg
DunnO
DunnOOP3y ago
cje
cje3y ago
Whatever the function you’re calling expects, possibly just an empty object
DunnO
DunnOOP3y ago
DunnO
DunnOOP3y ago
DunnO
DunnOOP3y ago
Its expecting (opts: CreateNextContextOptions)
DunnO
DunnOOP3y ago
barry
barry3y ago
const ssg = createProxySSGHelpers({
router: appRouter,
transformer: superjson,
ctx: await createContextInner({ session: null }),
});
const ssg = createProxySSGHelpers({
router: appRouter,
transformer: superjson,
ctx: await createContextInner({ session: null }),
});
cje
cje3y ago
^ yea that You can’t use regular createContext because you don’t have req and res
barry
barry3y ago
createContextInner I don't see createContextInner anywhere in docs though. <:bing_shrug:583791581497393162>
DunnO
DunnOOP3y ago
You guys are legends That worked for me I will continue and see if I can pre load the fetch in the server
Want results from more Discord servers?
Add your server